-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
epoch, duration: improve and fix serdes feature #175
Conversation
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Hello @ChristopherRabotin, the serdes traits for In the previous code I don't understand why all of these options were depending on "std" instead of "serde".
|
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.
Deriving serde is definitely nicer than the custom implementations I had. Could you add some tests for the new serialization because it seems like I removed those.
@@ -159,6 +159,7 @@ const CUMULATIVE_DAYS_FOR_MONTH: [u16; 12] = { | |||
#[derive(Copy, Clone, Eq)] | |||
#[repr(C)] | |||
#[cfg_attr(feature = "python", pyclass)] | |||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
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.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | |
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] |
@@ -57,6 +57,7 @@ pub const NANOSECONDS_PER_CENTURY: u64 = DAYS_PER_CENTURY_U64 * NANOSECONDS_PER_ | |||
#[derive(Clone, Copy, Debug, PartialOrd, Eq, Ord)] | |||
#[repr(C)] | |||
#[cfg_attr(feature = "python", pyclass)] | |||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
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.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | |
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] |
Yes! I think that was missing. Also, this issue should have been caught in the tests, but I know that the tests for serde are crappy ... actually did I remove the test? I don't see it right now!
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.
you mean the actual code (1) ? or in the CI logs (2) ?
(1) the code is now replaced by test methods that will get triggered if a CI jobs enables the serde feature.
(2) apparently the previous CI --with-non-default stopped at "std" and did not resolve "std->serde"
@@ -21,8 +21,8 @@ use core::fmt; | |||
use core::hash::{Hash, Hasher}; | |||
use core::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign}; | |||
|
|||
#[cfg(feature = "std")] | |||
use serde::{de, Deserialize, Deserializer}; | |||
#[cfg(feature = "serde")] |
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.
#[cfg(feature = "serde")] | |
#[cfg(feature = "std")] |
There isn't any "serde" feature in the Cargo.toml
so I'm guessing that this line causes the serde imports to never be executed.
From Cargo.toml:
[features]
default = ["std"]
std = ["serde", "serde_derive"]
asn1der = ["der"]
python = ["std", "asn1der", "pyo3"]
When the "std" feature is enabled, it should be importing serde, but I think that you've nailed the source of the issue with your change in Duration (I'll write another comment).
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.
Hello Chris
the following only works when the feature bears a crate exact name.
See my rinex Cargo.tml
"flate2" and "serde" are two features, apparently no declaration, but this is unlocked with "optionnal=true" when summoning these libraries.
Set your default behavior in [features] and they behavior in this case (this is important).
Set whatever features they might come with, for instance "derive" for "serdes" is rapidly needed.
See the "with-geo" feature I declared too, which is the combination of two packages, and I don't know how to manage this case, so I declared a "custom" feature
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.
Well I'll add one thing.
With your current Cargo.toml "Serde::Serialize" and "Deseriliaze" are imported by "std": that answers my initial question.
Removing these two would actually work too, with my previous explanation
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.
Wow, I had no idea! I've been developing in Rust since 2017 but I learn new things regularly. Thanks
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.
Same thing here..
rust_docs
clearly lacks some capabilities regarding crate features. They are totally undocumented in the API. Like there is absolutely no mean to know what is available besides reading the Cargo.toml..
There is a rust crate that allows documenting a crate feature, it parses documentation off Cargo.toml, so it will grow a little too much IMO. And it's also one more dependency required for your crate. I think they should come with a solution to this problem in a near future
@@ -28,8 +28,8 @@ use pyo3::prelude::*; | |||
#[cfg(feature = "python")] | |||
use pyo3::pyclass::CompareOp; | |||
|
|||
#[cfg(feature = "std")] | |||
use serde::{de, Deserialize, Deserializer}; | |||
#[cfg(feature = "serde")] |
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.
#[cfg(feature = "serde")] | |
#[cfg(feature = "std")] |
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.
so in conclusion, "serde" already exists in the current Cargo.toml
and it's usually invoked with "serde"
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Codecov ReportBase: 78.57% // Head: 79.26% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #175 +/- ##
==========================================
+ Coverage 78.57% 79.26% +0.68%
==========================================
Files 9 9
Lines 2586 2580 -6
==========================================
+ Hits 2032 2045 +13
+ Misses 554 535 -19
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
.github/workflows/tests.yml
Outdated
@@ -61,6 +61,9 @@ jobs: | |||
|
|||
- name: Test (no default features) | |||
run: cargo test --no-default-features | |||
|
|||
- name: Test (all features) | |||
run: cargo test --all-features |
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.
The python
feature can only be built with the PyO3 tools. So this line needs to be all of the features, minus the python
feature.
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.
Apparently --no-default-features only tests "std" (that is my understanding)
Maybe we should create a dedicated step like "ANS1" ? I don't know
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.
Yes, that would also work
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Merging in a minute, thanks for that fix. Let me know when you need a release and I'll update the change log, make a tag, and publish. |
Signed-off-by: Guillaume W. Bres guillaume.bressaix@gmail.com