Skip to content

Commit

Permalink
Merge pull request #356 from JonathanWoollett-Light/hashmap-from
Browse files Browse the repository at this point in the history
fix: Use `HashMap::from`
  • Loading branch information
arlyon authored Mar 23, 2023
2 parents 78eb351 + 0c8dc9d commit e7c6456
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
19 changes: 12 additions & 7 deletions examples/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ async fn main() {
description: Some(
"A fake customer that is used to illustrate the examples in async-stripe.",
),
metadata: Some(
[("async-stripe".to_string(), "true".to_string())].iter().cloned().collect(),
),
metadata: Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)])),

..Default::default()
},
Expand All @@ -43,17 +44,21 @@ async fn main() {
// create a new exmaple project
let product = {
let mut create_product = CreateProduct::new("T-Shirt");
create_product.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
create_product.metadata = Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)]));
Product::create(&client, create_product).await.unwrap()
};

// and add a price for it in USD
let price = {
let mut create_price = CreatePrice::new(Currency::USD);
create_price.product = Some(IdOrCreate::Id(&product.id));
create_price.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
create_price.metadata = Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)]));
create_price.unit_amount = Some(1000);
create_price.expand = &["product"];
Price::create(&client, create_price).await.unwrap()
Expand Down
14 changes: 8 additions & 6 deletions examples/customer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ async fn main() {
description: Some(
"A fake customer that is used to illustrate the examples in async-stripe.",
),
metadata: Some(
[("async-stripe".to_string(), "true".to_string())].iter().cloned().collect(),
),
metadata: Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)])),

..Default::default()
},
Expand All @@ -42,9 +43,10 @@ async fn main() {
description: Some(
"A fake customer that is used to illustrate the examples in async-stripe.",
),
metadata: Some(
[("async-stripe".to_string(), "true".to_string())].iter().cloned().collect(),
),
metadata: Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)])),

..Default::default()
},
Expand Down
7 changes: 4 additions & 3 deletions examples/payment-intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ async fn main() {
description: Some(
"A fake customer that is used to illustrate the examples in async-stripe.",
),
metadata: Some(
[("async-stripe".to_string(), "true".to_string())].iter().cloned().collect(),
),
metadata: Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)])),

..Default::default()
},
Expand Down
12 changes: 8 additions & 4 deletions examples/payment-link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ async fn main() {
// create a new example project
let product = {
let mut create_product = CreateProduct::new("T-Shirt");
create_product.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
create_product.metadata = Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)]));
Product::create(&client, create_product).await.unwrap()
};

// and add a price for it in USD
let price = {
let mut create_price = CreatePrice::new(Currency::USD);
create_price.product = Some(IdOrCreate::Id(&product.id));
create_price.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
create_price.metadata = Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)]));
create_price.unit_amount = Some(1000);
create_price.expand = &["product"];
Price::create(&client, create_price).await.unwrap()
Expand Down
19 changes: 12 additions & 7 deletions examples/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ async fn main() {
description: Some(
"A fake customer that is used to illustrate the examples in async-stripe.",
),
metadata: Some(
[("async-stripe".to_string(), "true".to_string())].iter().cloned().collect(),
),
metadata: Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)])),

..Default::default()
},
Expand Down Expand Up @@ -76,17 +77,21 @@ async fn main() {
// create a new exmaple project
let product = {
let mut create_product = CreateProduct::new("Monthly T-Shirt Subscription");
create_product.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
create_product.metadata = Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)]));
Product::create(&client, create_product).await.unwrap()
};

// and add a price for it in USD
let price = {
let mut create_price = CreatePrice::new(Currency::USD);
create_price.product = Some(IdOrCreate::Id(&product.id));
create_price.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
create_price.metadata = Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)]));
create_price.unit_amount = Some(1000);
create_price.recurring = Some(CreatePriceRecurring {
interval: CreatePriceRecurringInterval::Month,
Expand Down

0 comments on commit e7c6456

Please sign in to comment.