DeterminateSystems / bootspec

Implementation of RFC-0125's datatype and synthesis tooling.
MIT License
24 stars 5 forks source link

bootspec(generation): offer TryInto conversion from Generation to any… #109

Closed RaitoBezarius closed 1 year ago

RaitoBezarius commented 1 year ago
Description

… schema version

Enables replacing:

        // TODO: replace me when https://github.com/DeterminateSystems/bootspec/pull/109 lands.
        let bootspec: BootSpec = match boot_json.generation {
            BootspecGeneration::V1(bootspec) => bootspec,
            _ => return Err(anyhow!("Unsupported bootspec schema"))
        };

by

        let bootspec: BootSpec = boot_json.generation.try_into().map_err(|err| ...);
Checklist
lheckemann commented 1 year ago

Looks good (just needs a cargo fmt), any other reason it's still a draft?

RaitoBezarius commented 1 year ago

Looks good (just needs a cargo fmt), any other reason it's still a draft?

It was more like a discussion on whether this PR is a good idea and I made it in 2 minutes so I was not sure of the quality :-)

cole-h commented 1 year ago

I was wrong about TryFrom making us able to get rid of the "manually add a new impl block for each variant", but there is a derive_more crate that can help with this. I've opened https://github.com/DeterminateSystems/bootspec/pull/120 which should do what you want.