diff options
author | Teddy Wing | 2018-11-08 01:10:48 +0100 |
---|---|---|
committer | Teddy Wing | 2018-11-08 01:10:48 +0100 |
commit | cb4cffe9aae7b1e345a2cf01811c60c7ef7c2d25 (patch) | |
tree | c4403d4a69144416b4106d9f9cdd2b16b823e21c | |
parent | 84a22d31e249da180c128deb759e1fd6f92a9ff1 (diff) | |
download | dome-key-web-cb4cffe9aae7b1e345a2cf01811c60c7ef7c2d25.tar.bz2 |
paddle::php_serialize(): Take an `IntoIterator` argument
Replace the `ExactSizeIterator` with an `IntoIterator`, as I wasn't able
to pass in a `HashMap` with `ExactSizeIterator`.
While we lose the convenience of the `len()` method, it's easy enough to
just count the length of the iterator while we're serializing the
entries within it.
-rw-r--r-- | license-generator/paddle/src/lib.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/license-generator/paddle/src/lib.rs b/license-generator/paddle/src/lib.rs index ebb0f01..d153895 100644 --- a/license-generator/paddle/src/lib.rs +++ b/license-generator/paddle/src/lib.rs @@ -1,17 +1,14 @@ // https://paddle.com/docs/reference-verifying-webhooks/ fn verify_signature<'a, I>(params: I) -> bool -where I: ExactSizeIterator<Item = (&'a str, &'a str)> { +where I: IntoIterator<Item = (&'a str, &'a str)> { false } fn php_serialize<'a, I>(pairs: I) -> String -where I: ExactSizeIterator<Item = (&'a str, &'a str)> { +where I: IntoIterator<Item = (&'a str, &'a str)> { let mut serialized = String::with_capacity(500); - serialized.push_str( - &format!("a:{pairs_count}:{{", pairs_count = pairs.len()) - ); - + let mut len = 0; for (key, value) in pairs { serialized.push_str( &format!( @@ -22,11 +19,17 @@ where I: ExactSizeIterator<Item = (&'a str, &'a str)> { value = value ) ); + + len += 1; } serialized.push_str("}"); - serialized + format!( + "a:{pairs_count}:{{{rest}", + pairs_count = len, + rest = serialized + ) } |