Skip to content

Commit 2e15c3c

Browse files
committed
Cargo fmt
1 parent f91e126 commit 2e15c3c

File tree

14 files changed

+183
-167
lines changed

14 files changed

+183
-167
lines changed

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

checkout/rust/cart-transform/bundles/src/main.rs

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use shopify_function::prelude::*;
2-
use shopify_function::Result;
1+
use crate::input::InputCart as Cart;
2+
use crate::input::InputCartLinesMerchandise::ProductVariant;
3+
use crate::input::InputCartLinesMerchandiseOnProductVariant;
34
use crate::output::CartLineInput;
4-
use crate::output::PriceAdjustment;
5-
use crate::output::PriceAdjustmentValue;
65
use crate::output::CartOperation;
76
use crate::output::ExpandOperation;
87
use crate::output::ExpandedItem;
98
use crate::output::MergeOperation;
10-
use crate::input::InputCart as Cart;
11-
use crate::input::InputCartLinesMerchandiseOnProductVariant;
12-
use crate::input::InputCartLinesMerchandise::ProductVariant as ProductVariant;
9+
use crate::output::PriceAdjustment;
10+
use crate::output::PriceAdjustmentValue;
1311
use serde::{Deserialize, Serialize};
12+
use shopify_function::prelude::*;
13+
use shopify_function::Result;
1414

1515
generate_types!(
1616
query_path = "./input.graphql",
@@ -55,10 +55,12 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
5555
let mut cart_operations: Vec<CartOperation> = get_merge_cart_operations(&input.cart);
5656
cart_operations.extend(get_expand_cart_operations(&input.cart));
5757

58-
Ok(output::FunctionResult { operations: Some(cart_operations) })
59-
}
58+
Ok(output::FunctionResult {
59+
operations: Some(cart_operations),
60+
})
61+
}
6062

61-
// merge operation logic
63+
// merge operation logic
6264

6365
fn get_merge_cart_operations(cart: &Cart) -> Vec<CartOperation> {
6466
let merge_parent_defintions: Vec<ComponentParent> = get_merge_parent_definitions(cart);
@@ -80,8 +82,8 @@ fn get_merge_cart_operations(cart: &Cart) -> Vec<CartOperation> {
8082
if let Some(price_adjustment) = &definition.price_adjustment {
8183
price = Some(PriceAdjustment {
8284
percentage_decrease: Some(PriceAdjustmentValue {
83-
value: (*price_adjustment).to_string()
84-
})
85+
value: (*price_adjustment).to_string(),
86+
}),
8587
});
8688
}
8789

@@ -93,17 +95,17 @@ fn get_merge_cart_operations(cart: &Cart) -> Vec<CartOperation> {
9395
price: price,
9496
};
9597

96-
result.push(CartOperation {merge: Some(merge_operation), expand: None});
98+
result.push(CartOperation {
99+
merge: Some(merge_operation),
100+
expand: None,
101+
});
97102
}
98103
}
99104

100105
return result;
101106
}
102107

103-
fn get_components_in_cart(
104-
cart: &Cart,
105-
definition: &ComponentParent,
106-
) -> Vec<CartLineInput> {
108+
fn get_components_in_cart(cart: &Cart, definition: &ComponentParent) -> Vec<CartLineInput> {
107109
let mut line_results: Vec<CartLineInput> = Vec::new();
108110
for (reference, quantity) in definition
109111
.component_reference
@@ -120,13 +122,13 @@ fn get_components_in_cart(
120122
}
121123

122124
if let Some(merchandise) = &variant {
123-
if reference == &merchandise.id && &line.quantity >= quantity {
124-
line_results.push(CartLineInput {
125-
cart_line_id: line.id.clone(),
126-
quantity: quantity.clone(),
127-
});
128-
break;
129-
}
125+
if reference == &merchandise.id && &line.quantity >= quantity {
126+
line_results.push(CartLineInput {
127+
cart_line_id: line.id.clone(),
128+
quantity: quantity.clone(),
129+
});
130+
break;
131+
}
130132
}
131133
}
132134
}
@@ -154,7 +156,9 @@ fn get_merge_parent_definitions(cart: &Cart) -> Vec<ComponentParent> {
154156
return merge_parent_defintions;
155157
}
156158

157-
fn get_component_parents(variant: &InputCartLinesMerchandiseOnProductVariant) -> Vec<ComponentParent> {
159+
fn get_component_parents(
160+
variant: &InputCartLinesMerchandiseOnProductVariant,
161+
) -> Vec<ComponentParent> {
158162
let mut component_parents: Vec<ComponentParent> = Vec::new();
159163
if let Some(component_parents_metafield) = &variant.component_parents {
160164
let value: Vec<ComponentParentMetafield> =
@@ -196,13 +200,17 @@ fn get_expand_cart_operations(cart: &Cart) -> Vec<CartOperation> {
196200
let component_references: Vec<ID> = get_component_references(&merchandise);
197201
let component_quantities: Vec<i64> = get_component_quantities(&merchandise);
198202

199-
if component_references.is_empty() || component_references.len() != component_quantities.len() {
203+
if component_references.is_empty()
204+
|| component_references.len() != component_quantities.len()
205+
{
200206
continue;
201207
}
202208

203209
let mut expand_relationships: Vec<ExpandedItem> = Vec::new();
204210

205-
for (reference, quantity) in component_references.iter().zip(component_quantities.iter()) {
211+
for (reference, quantity) in
212+
component_references.iter().zip(component_quantities.iter())
213+
{
206214
let expand_relationship: ExpandedItem = ExpandedItem {
207215
merchandise_id: reference.clone(),
208216
quantity: quantity.clone(),
@@ -213,13 +221,16 @@ fn get_expand_cart_operations(cart: &Cart) -> Vec<CartOperation> {
213221

214222
let price: Option<PriceAdjustment> = get_price_adjustment(&merchandise);
215223

216-
let expand_operation: ExpandOperation = ExpandOperation{
224+
let expand_operation: ExpandOperation = ExpandOperation {
217225
cart_line_id: line.id.clone(),
218226
expanded_cart_items: expand_relationships,
219227
price: price,
220228
};
221229

222-
result.push(CartOperation {expand: Some(expand_operation), merge: None});
230+
result.push(CartOperation {
231+
expand: Some(expand_operation),
232+
merge: None,
233+
});
223234
}
224235
}
225236

@@ -242,13 +253,15 @@ fn get_component_references(variant: &InputCartLinesMerchandiseOnProductVariant)
242253
return Vec::new();
243254
}
244255

245-
fn get_price_adjustment(variant: &InputCartLinesMerchandiseOnProductVariant) -> Option<PriceAdjustment> {
256+
fn get_price_adjustment(
257+
variant: &InputCartLinesMerchandiseOnProductVariant,
258+
) -> Option<PriceAdjustment> {
246259
if let Some(price_adjustment) = &variant.price_adjustment {
247-
return Some(PriceAdjustment {
248-
percentage_decrease: Some(PriceAdjustmentValue {
249-
value: price_adjustment.value.parse().unwrap()
250-
})
251-
});
260+
return Some(PriceAdjustment {
261+
percentage_decrease: Some(PriceAdjustmentValue {
262+
value: price_adjustment.value.parse().unwrap(),
263+
}),
264+
});
252265
}
253266

254267
return None;

checkout/rust/delivery-customization/default/src/main.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ generate_types!(
1010

1111
#[derive(Serialize, Deserialize, Default, PartialEq)]
1212
#[serde(rename_all(deserialize = "camelCase"))]
13-
struct Configuration {
14-
15-
}
13+
struct Configuration {}
1614

1715
impl Configuration {
1816
fn from_str(value: &str) -> Self {
@@ -25,11 +23,12 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
2523
let no_changes = output::FunctionResult { operations: vec![] };
2624

2725
let _config = match input.delivery_customization.metafield {
28-
Some(input::InputDeliveryCustomizationMetafield { value }) =>
29-
Configuration::from_str(&value),
26+
Some(input::InputDeliveryCustomizationMetafield { value }) => {
27+
Configuration::from_str(&value)
28+
}
3029
None => return Ok(no_changes),
3130
};
32-
31+
3332
Ok(output::FunctionResult { operations: vec![] })
3433
}
3534

checkout/rust/payment-customization/default/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ generate_types!(
1010

1111
#[derive(Serialize, Deserialize, Default, PartialEq)]
1212
#[serde(rename_all(deserialize = "camelCase"))]
13-
struct Configuration {
14-
15-
}
13+
struct Configuration {}
1614

1715
impl Configuration {
1816
fn from_str(value: &str) -> Self {
@@ -25,8 +23,9 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
2523
let no_changes = output::FunctionResult { operations: vec![] };
2624

2725
let _config = match input.payment_customization.metafield {
28-
Some(input::InputPaymentCustomizationMetafield { value }) =>
29-
Configuration::from_str(&value),
26+
Some(input::InputPaymentCustomizationMetafield { value }) => {
27+
Configuration::from_str(&value)
28+
}
3029
None => return Ok(no_changes),
3130
};
3231

discounts/rust/order-discounts/default/src/main.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ generate_types!(
88
schema_path = "./schema.graphql"
99
);
1010

11-
1211
#[derive(Serialize, Deserialize, Default, PartialEq)]
1312
#[serde(rename_all(deserialize = "camelCase"))]
14-
struct Configuration {
15-
16-
}
13+
struct Configuration {}
1714

1815
impl Configuration {
1916
fn from_str(value: &str) -> Self {
@@ -29,8 +26,7 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
2926
};
3027

3128
let _config = match input.discount_node.metafield {
32-
Some(input::InputDiscountNodeMetafield { value }) =>
33-
Configuration::from_str(&value),
29+
Some(input::InputDiscountNodeMetafield { value }) => Configuration::from_str(&value),
3430
None => return Ok(no_discount),
3531
};
3632

@@ -41,4 +37,4 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
4137
}
4238

4339
#[cfg(test)]
44-
mod tests;
40+
mod tests;

discounts/rust/order-discounts/fixed-amount/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ mod tests {
8383
input::Input {
8484
discount_node: input::DiscountNode {
8585
metafield: Some(input::Metafield {
86-
value: serde_json::to_string(&config.unwrap_or_default()).unwrap()
86+
value: serde_json::to_string(&config.unwrap_or_default()).unwrap(),
8787
}),
8888
},
8989
presentment_currency_rate: presentment_currency_rate.unwrap_or(1.00),
@@ -150,10 +150,10 @@ mod tests {
150150
}
151151
"#;
152152

153-
let expected_input = input(
154-
Some(Configuration { value: 10.00 }),
155-
Some(2.00)
153+
let expected_input = input(Some(Configuration { value: 10.00 }), Some(2.00));
154+
assert_eq!(
155+
expected_input,
156+
serde_json::from_str::<input::Input>(input_json).unwrap()
156157
);
157-
assert_eq!(expected_input, serde_json::from_str::<input::Input>(input_json).unwrap());
158158
}
159159
}

discounts/rust/product-discounts/default/src/main.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ generate_types!(
88
schema_path = "./schema.graphql"
99
);
1010

11-
1211
#[derive(Serialize, Deserialize, Default, PartialEq)]
1312
#[serde(rename_all(deserialize = "camelCase"))]
14-
struct Configuration {
15-
16-
}
13+
struct Configuration {}
1714

1815
impl Configuration {
1916
fn from_str(value: &str) -> Self {
@@ -29,8 +26,7 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
2926
};
3027

3128
let _config = match input.discount_node.metafield {
32-
Some(input::InputDiscountNodeMetafield { value }) =>
33-
Configuration::from_str(&value),
29+
Some(input::InputDiscountNodeMetafield { value }) => Configuration::from_str(&value),
3430
None => return Ok(no_discount),
3531
};
3632

@@ -41,4 +37,4 @@ fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
4137
}
4238

4339
#[cfg(test)]
44-
mod tests;
40+
mod tests;

0 commit comments

Comments
 (0)