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

bootspec: offer TryInto conversion from Generation to any schema version #120

Merged
merged 1 commit into from
May 20, 2023

Conversation

cole-h
Copy link
Member

@cole-h cole-h commented May 18, 2023

This utilizes the derive_more crate so that we don't have to manually add new implementations for each version.

Description

Closes #109.

Checklist
  • Built with cargo build
  • Formatted with cargo fmt
  • Linted with cargo clippy
  • Ran tests with cargo test
  • Added or updated relevant tests (leave unchecked if not applicable)
  • Added or updated relevant documentation (leave unchecked if not applicable)

bootspec/src/generation.rs Outdated Show resolved Hide resolved
impl TryFrom<Generation> for v1::GenerationV1 {
type Error = crate::BootspecError;

fn try_from(value: Generation) -> Result<Self, Self::Error> {
Copy link
Member Author

Choose a reason for hiding this comment

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

While this current implementation is infallible (because we don't have any other variants), it will be come fallible as soon as we add a new variant.

@cole-h
Copy link
Member Author

cole-h commented May 20, 2023

I just realized that "any" here is kinda incorrect... Since deserializing the BootSpec will only return the latest generation version. So, once we have one more version, it will only ever deserialize the latest version (the first one in the enum) (if it exists)...

Maybe for v2 we should change BootSpec's generation field to be a Vec<Generation>... I think that might require a custom deserializer, but it also might not. Then we could maybe provide a helper function for "give me version X if it exists (and error otherwise)"...

@cole-h
Copy link
Member Author

cole-h commented May 20, 2023

I think this is "not bad" for the moment, though. Assuming @RaitoBezarius doesn't report anything wrong with it, I'll probably cut a 1.0.0 tomorrow.

@cole-h cole-h merged commit 45e6c93 into main May 20, 2023
5 checks passed
@cole-h cole-h deleted the impl-tryfrom branch May 20, 2023 15:57
@RaitoBezarius
Copy link
Contributor

Will give it a try in some minutes.

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

2 participants