-
Notifications
You must be signed in to change notification settings - Fork 85
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
deer
: implement Deserialize
for core::time
#2390
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
77475ec
feat: init cell
indietyp ef0fe4b
feat: pull in code from #1875
indietyp 4bd5ada
feat: test cells
indietyp fea5bf1
test: unsafe variants
indietyp 88c80fe
test: reflection passthrough
indietyp 8fbfad9
fix: lint
indietyp 61a5937
Update test_impls_core_cell.rs
indietyp 3ec049a
chore: convert from #1875
indietyp f2c26be
test: duration deserialization
indietyp d6c9ef9
test: time via approx
indietyp 3058a09
fix: miri
indietyp 32772ce
Merge branch 'main' into bm/deer/core-time
indietyp 19a73ed
Merge branch 'main' into bm/deer/core-time
indietyp 9048070
feat: implement relative assert ourselves
indietyp 31d502e
chore: grammar c:
indietyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ mod non_zero; | |
mod option; | ||
mod string; | ||
mod sync; | ||
mod time; | ||
mod unit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use core::time::Duration; | ||
|
||
use error_stack::Result; | ||
|
||
use crate::{error::DeserializeError, Deserialize, Deserializer}; | ||
|
||
impl<'de> Deserialize<'de> for Duration { | ||
type Reflection = <f64 as Deserialize<'de>>::Reflection; | ||
|
||
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, DeserializeError> { | ||
f64::deserialize(de).map(Self::from_secs_f64) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use core::time::Duration; | ||
|
||
use approx::assert_relative_eq; | ||
use deer_desert::{assert_tokens_with_assertion, Token}; | ||
use proptest::prelude::*; | ||
|
||
#[cfg(not(miri))] | ||
proptest! { | ||
#[test] | ||
fn duration_ok(value in any::<Duration>()) { | ||
let input = value.as_secs_f64(); | ||
|
||
assert_tokens_with_assertion(|received: Duration| { | ||
assert_relative_eq!(received.as_secs_f64(), value.as_secs_f64()); | ||
}, &[Token::Number(input.into())]); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is
approx
used in future implementations? Or can we simply doa - b < f64:EPSILON
for f64 comparisons?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.
nope not at all, we can indeed just use
a - b < f64:EPSILON
. Good catch!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.
fixed in 9048070