-
Notifications
You must be signed in to change notification settings - Fork 25
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
Switch to serde for serialization/deserialization #3
Conversation
Oh, and one thing I'd like to change here too: the response from FCM has a reason, which could basically be an enum. This would be another breaking change to our API here, but would be much nicer to work with in your application. |
I don't quite understand the reasoning behind taking Box in that API. Why wouldn't this work: pub fn data<T: Serialize>(&mut self, data: T) -> Result<&mut MessageBuilder, serde_json::Error> { … } It would mirror the signature of edit: |
Reviewed 8 of 10 files at r1. src/lib.rs, line 41 at r1 (raw file):
src/message/mod.rs, line 186 at r1 (raw file):
Comments from Reviewable |
Review status: 8 of 10 files reviewed at latest revision, 5 unresolved discussions. examples/simple_sender.rs, line 37 at r1 (raw file):
src/message/mod.rs, line 183 at r1 (raw file):
src/message/tests.rs, line 40 at r1 (raw file):
Comments from Reviewable |
You were totally right about that |
Are you talking about the response reasons that are mentioned here in Table 4 for status code 400? |
Reviewed 4 of 4 files at r2. src/message/mod.rs, line 186 at r1 (raw file): Previously, panicbit wrote…
What about the unused lifetime parameter? Comments from Reviewable |
Missed that lifetime parameter. Fixed. For the enum, if it would be possible to have one that is |
You could do that, but then adding a new variant can potentially lead to bugs. If someone is matching against OTOH, while providing the most flexibility, using consts allows for using the API the wrong way (e.g. by not using the available constants). Maybe we would provide a function that gives you an enum with an opaque/private Other variant (so that nobody can match against its contents) and also provide a function to get the raw string. It would be nice to have RFC 2008 implemented. OK, so my final thought is: If RFC 2008 gets implemented it's probably best to use an enum, and even if it is not, this crate is still pre 1.0 so we can still more or less freely break stuff. So I'm fine with an enum for now. |
Well, it's pre 1.0, but we push millions of notifications through this library and my consumer every day. So let's try to make it right still :) |
So what do you think is the best option? After thinking about RFC 2008 a bit more it doesn't seem to be that useful in our case. I think we should simply make the contents of the Here's some code for clarification: Setup: enum Reason {
Foo,
Bar,
Other(OpaqueReason),
} Case 1, exhaustive (ok): match reason {
Reason::Foo => …,
Reason::Bar => …,
Reason::Other(..) => {
// acquire raw reason somehow and deal with it
}
} Adding a new variant in case 1 causes a compile-time error, which I think is good. Case 2, wildcard (ok): match reason {
Reason::Foo => …,
Reason::Bar => …,
_ => {
// acquire raw reason somehow and deal with it
}
} Adding a new variant in case 2 wouldn't have an effect. The code would still be able to observe the expected reasons. Case 3, wildcard (bad): match reason {
Reason::Foo => …,
Reason::Other => {
// acquire raw reason somehow and deal with it
},
_ => {} // Ignore other errors
} Adding a new variant in case 3 could cause the We could also hide the |
Reviewed 3 of 3 files at r3. Comments from Reviewable |
Reviewed 1 of 1 files at r4. Comments from Reviewable |
The enums in responses are not done quickly. I need to think this whole Response thingy a bit more here. If you're happy with this pull request, go ahead and merge it, I'll try it on production then ;) |
rustc_serialize
is deprecated,serde
taking it's place as the serialization solution. Using serde's nice macros we don't need our own JSON serialization code.I could almost completely make the shift without breaking the API, but the custom data setup I had to change to accept anything that is deriving the
Serialize
functionality, so what that means is:Box
just so we can use almost anything that can be serialized as a parameterI did a pull request to open up discussion first. This requires a major version change because of that broken API. I can bump the version and publish a new version if this looks OK to you.
This change is