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

Strongly-typed enums for registry data #17

Open
ErichDonGubler opened this issue Jan 11, 2018 · 1 comment
Open

Strongly-typed enums for registry data #17

ErichDonGubler opened this issue Jan 11, 2018 · 1 comment

Comments

@ErichDonGubler
Copy link

Hey there! I have a design-related question which I hope may eventually result in a contribution to enhance this codebase. This issue can be closed when maintainers have a consensus on whether or not this would be useful. :)

Recently, I've been developing some code in Rust that can parse Registry.pol files, and found it immensely useful to have a enum that models the data actually associated with registry values. It would be something along the lines of this:

pub enum RegistryData {
RegNone,
RegSz(String),
RegExpandSz(String),
RegBinary(Vec),
RegDwordLittleEndian(u32),
RegDwordBigEndian(u32),
RegLink(String),
RegMultiSz(Vec),
RegResourceList,
RegFullResourceDescriptor,
RegResourceRequirementsList,
RegQword(u64),
}

The key benefit I see to this model is that it allows more specific and strong types for usage with the domain that this crate handles. This is especially useful for testing -- some of the code I might write to test a sample data file in my parser might like this, and I think it's pretty easy to follow:

let parsed_reg_pol_file = RegistryPolicyFile::from_buffer(File::open("Registry.pol")?)?;
assert_eq(parsed_reg_pol_file.configuration_settings. == vec![
	RegSz("Some value"),
    RegExpandSz("APPDATA"),
	RegDword(25u32),
    RegMultiSz(vec!["just", "some", "words"]),
    // etc.
]);

This enum is not intended to replace the unparsed types like the RegValue struct or the RegType enum -- but it would be convenient to users who don't need or intend to use the intermediate types. I already have conversions defined to this enum from sequences of bytes, which might be interesting to compare with the implementation that's in this project.

There are other details I would love to discuss, too -- but first, I want to know if this is even something interesting for the winreg crate's authors! I certainly thing it would be for users.

@gentoo90
Copy link
Owner

Yes, I think this can be a part of winreg. When I started writing it I was thinking of a similar enum but ended up with RegValue struct just because it was easier to implement and I didn't need to actually use raw values anywhere outside of the crate.

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

No branches or pull requests

2 participants