-
Notifications
You must be signed in to change notification settings - Fork 63
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
NoneAsEmptyString: Deserialize using FromStr #316
Conversation
Codecov Report
@@ Coverage Diff @@
## master #316 +/- ##
==========================================
+ Coverage 79.24% 79.39% +0.15%
==========================================
Files 45 45
Lines 2587 2577 -10
==========================================
- Hits 2050 2046 -4
+ Misses 537 531 -6
Continue to review full report at Codecov.
|
Thanks for informing me about this mistake. I'm happy the crate is otherwise useful though :) I'm actually unsure what the best fix here is. Honoring the documentation and keeping it consistent with The documentation is written mainly for
|
Thanks for the quick reply and the research! I'm working with If both behaviors are useful, we could just introduce a second type. I am not sure what would be a good name, maybe On further thought, this might be possible to do in a modular fashion. I'm thinking about |
Oh, Using |
bea1829
to
b945c18
Compare
All right. I pushed the change to relay deserialization of Couldn't |
Thanks for updating the PR. I'm going to merge this as it and release a new bugfix version later. bors r+ Regarding Of course it is possible to create a type, which tries multiple serializing behaviors. It is much more uncommon for the serialization to fail though, so I am not sure how generally useful such a type would be. An example where serialization can fail are maps with non-string keys when using JSON, but this is caused by the I'm not sure it would work for your case though. The first argument, |
316: NoneAsEmptyString: Deserialize using FromStr r=jonasbb a=mkroening The docs for `NoneAsEmptyString` are wrong. For deserialization `for<'a> From<&'a str>` is used instead of `FromStr`. In my case, only `FromStr` is available, so I have to use `rust::string_empty_as_none` instead. Those docs advertise identical functionality using `NoneAsEmptyString`, so that advertisement either needs to be removed or `NoneAsEmptyStrings` functionality adjusted. Which would you prefer? PS: Thanks for this awesome project! :) Co-authored-by: Martin Kröning <mkroening@posteo.net>
Build failed: |
bors r+ |
Build succeeded: |
Ah, I see. Thanks for explaining. I just found this idea interesting to explore. For my use case I am happy with the behavior introduced by this PR though. Thanks a lot for your help! :) |
The docs for
NoneAsEmptyString
are wrong. For deserializationfor<'a> From<&'a str>
is used instead ofFromStr
.In my case, only
FromStr
is available, so I have to userust::string_empty_as_none
instead. Those docs advertise identical functionality usingNoneAsEmptyString
, so that advertisement either needs to be removed orNoneAsEmptyStrings
functionality adjusted.Which would you prefer?
PS: Thanks for this awesome project! :)