-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Serde to 1.0 #28
Conversation
Fixed!
```
error: `s` does not live long enough
--> src/serialization.rs:31:18
|
31 | Ok(from_str(&s)?)
| ^ does not live long enough
32 | }
| - borrowed value only lives until here
|
note: borrowed value must be valid for the lifetime 'a as defined on the body at 27:85...
--> src/serialization.rs:27:86
|
27 | pub fn from_jwt_part<'a, B: AsRef, T: Deserialize<'a>>(encoded: B) -> Result {
| ______________________________________________________________________________________^ starting here...
28 | | let decoded = base64::decode_config(encoded.as_ref(), base64::URL_SAFE_NO_PAD)?;
29 | | let s = String::from_utf8(decoded)?;
30 | |
31 | | Ok(from_str(&s)?)
32 | | }
| |_^ ...ending here
error:
|
Thanks! Is that how it's meant to be used @dtolnay (sorry for the random ping)? |
I always appreciate a ping! Yes, both I will leave a few review comments as well. |
src/lib.rs
Outdated
algorithm: Algorithm, | ||
validation: &Validation) | ||
-> Result<TokenData<T>> | ||
where for<'a> T: Deserialize<'a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be more readable as T: DeserializeOwned
. This function requires that T
can deserialize without borrowing any data because the string it is deserialized from is thrown away before this function returns.
src/serialization.rs
Outdated
use header::Header; | ||
|
||
|
||
/// The return type of a successful call to decode | ||
#[derive(Debug)] | ||
pub struct TokenData<T: Deserialize> { | ||
pub struct TokenData<T> | ||
where for<'a> T: Deserialize<'a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bound should not be here. Structs in Rust should never have trait bounds. Trait bounds are for behavior.
impl<T> Data<T> where T: Behavior { /* behavior, okay */ }
fn behave<T>() where T: Behavior { /* also behavior, also okay */ }
struct Data<T> where T: Behavior { /* don't do this */ }
The only exception is things like Cow
that use associated types to define data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification. If it's not obvious, I'm new to Rust, and this result was me fighting with lifetime errors from the compiler 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed https://github.com/Manishearth/rust-clippy/issues/1689 to catch this case with a warning in Clippy. Apparently even the standard library does it wrong sometimes!
src/crypto.rs
Outdated
hmac::sign(&signing_key, signing_input.as_bytes()).as_ref(), | ||
base64::URL_SAFE_NO_PAD | ||
)) | ||
Ok(base64::encode_config(hmac::sign(&signing_key, signing_input.as_bytes()).as_ref(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next time please make whitespace changes in a separate commit. They makes it hard to find and review the thing you are actually changing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed on that, @mike-engel can you revert all the formatting changes for now?
Is it rustfmt using the latest config? I thought it would be more block indented than that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block style is currently recommended by the fmt-rfc folks but not the default in rustfmt. This is the settings they recommend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More official source I guess: here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry about that! Turns out my rustfmt was old. Would you prefer me to avoid rustfmt altogether, or add a config like the two linked from serde & rustmft?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid it for now please, we can run it later
Ok, updated now with Tests and benchmarks run fine. If there's anything else you'd like me to fix/edit/add, let me know. |
src/serialization.rs
Outdated
@@ -10,7 +10,7 @@ use header::Header; | |||
|
|||
/// The return type of a successful call to decode | |||
#[derive(Debug)] | |||
pub struct TokenData<T: Deserialize> { | |||
pub struct TokenData<T: DeserializeOwned> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bound should be removed: just pub struct TokenData<T> { ... }
. See https://github.com/Manishearth/rust-clippy/issues/1689.
Thanks to both of you! |
This is PR updates serde to 1.0. The README and Cargo file have been updated to use 1.0. This will close out #27.