Skip to content
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

Merged
merged 8 commits into from
Nov 17, 2022

Conversation

gwbres
Copy link
Collaborator

@gwbres gwbres commented Nov 15, 2022

Signed-off-by: Guillaume W. Bres guillaume.bressaix@gmail.com

Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
@gwbres
Copy link
Collaborator Author

gwbres commented Nov 15, 2022

Hello @ChristopherRabotin,

the serdes traits for Duration and Epoch do not work on my side.
When I try to import these two in structures that need serdes traits, it complains the traits are not implemented.

In the previous code I don't understand why all of these options were depending on "std" instead of "serde".

Timescale does work, I pushed it myself a couple of weeks ago using the auto derivation.
I modified the previous code to use auto derivation. I don't think we need a custom implementation either, the two structures are very straightforward and only comprise native types

Copy link
Member

@ChristopherRabotin ChristopherRabotin left a 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))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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!

Copy link
Collaborator Author

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")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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).

Copy link
Collaborator Author

@gwbres gwbres Nov 15, 2022

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

Copy link
Collaborator Author

@gwbres gwbres Nov 15, 2022

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

Copy link
Member

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

Copy link
Collaborator Author

@gwbres gwbres Nov 15, 2022

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")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[cfg(feature = "serde")]
#[cfg(feature = "std")]

Copy link
Collaborator Author

@gwbres gwbres Nov 15, 2022

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-commenter
Copy link

codecov-commenter commented Nov 15, 2022

Codecov Report

Base: 78.57% // Head: 79.26% // Increases project coverage by +0.68% 🎉

Coverage data is based on head (82593be) compared to base (e44444e).
Patch coverage: 100.00% of modified lines in pull request are covered.

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     
Impacted Files Coverage Δ
src/duration.rs 85.55% <100.00%> (+1.65%) ⬆️
src/epoch.rs 86.82% <100.00%> (+0.47%) ⬆️
src/timescale.rs 93.90% <100.00%> (+3.36%) ⬆️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -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
Copy link
Member

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.

Copy link
Collaborator Author

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

Copy link
Member

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

gwbres and others added 2 commits November 15, 2022 20:42
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Christopher Rabotin <christopher.rabotin@gmail.com>
@ChristopherRabotin
Copy link
Member

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.

@ChristopherRabotin ChristopherRabotin merged commit 7d6708c into nyx-space:master Nov 17, 2022
@gwbres gwbres deleted the serdes branch September 2, 2023 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants