Skip to content

How to convert String into PaymentIntentId #678

Discussion options

You must be logged in to vote

PaymentIntentId (and all the ***Id) implement FromStr, so you should be able to do one of these:

let id1: Result<PaymentIntentId, ParseIdError> = PaymentIntentId::from_str("pi_12345");
let id2: Result<PaymentIntentId, ParseIdError> = "pi_12345".parse();

Here is the definition:

async-stripe/src/ids.rs

Lines 92 to 98 in 84461ce

impl std::str::FromStr for $struct_name {
type Err = ParseIdError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok($struct_name(s.into()))
}
}

And here is a test example:

async-stripe/src/ids.rs

Lines 733 to 743 in 84461ce

fn test_parse_customer() {
assert!("cus_123".parse::<CustomerId>().is_ok());

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@blueowlgreenfish
Comment options

Answer selected by blueowlgreenfish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants