Skip to content

Conversation

Reisen
Copy link
Contributor

@Reisen Reisen commented Jun 2, 2023

This PR extends the Message type with features that are helpful to users consuming the program as a library.

  • Adds strum/serde to Message* during --features = library use.
  • Adds methods to extract id/publish_time from any message.
  • Exports the new MessageType enum generated by strum.

- Adds strum/serde during library use
- Adds methods to extract id/publish_time from any message.
[features]
debug = []
library = []
library = ["serde", "strum"]
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for having two "subfeatures" serde and strum.
Instead of using #[cfg(feature = "library")] in the code

Copy link
Contributor Author

@Reisen Reisen Jun 2, 2023

Choose a reason for hiding this comment

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

Just for the flexibility, It's nice in cases where for some reason one of these packages creates dependency conflicts with something the implementer is using, in reality most of the time someone is going to want both and will not have problems and will indeed just use library but this allows for this pattern:

// Strum only
pyth-oracle = { features = ["strum"] }

// Or if defaults ever get set:
pyth-oracle = { default-features = false, features = ["strum"] }

Etc.

Note post 1.60 versions of Cargo auto-define the following:

[features]
...
serde = ["dep:serde"]
strum = ["dep:strum"]

Copy link
Collaborator

Choose a reason for hiding this comment

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

well thinking more, no Message will be exported without library feature though, right?

Maybe we can keep serde separate but i was thinking maybe we can hide strum from users entirely :?

guibescos
guibescos previously approved these changes Jun 2, 2023
@Reisen Reisen force-pushed the reisen/oracle-library-features branch from 95a5d38 to 319cdc1 Compare June 2, 2023 13:05
guibescos
guibescos previously approved these changes Jun 2, 2023
@Reisen Reisen force-pushed the reisen/oracle-library-features branch from 319cdc1 to 1186585 Compare June 2, 2023 14:25
@ali-behjati ali-behjati merged commit 1bdac0d into main Jun 2, 2023
@ali-behjati ali-behjati deleted the reisen/oracle-library-features branch June 2, 2023 14:30
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.

3 participants