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

Add precise registry types and allocation-free queries and updates #3184

Merged
merged 4 commits into from
Aug 1, 2024

Conversation

kennykerr
Copy link
Collaborator

This update replaces some of the internals of the windows-registry crate to make it easier to query and update values with precise registry types and supports allocation-free queries and updates.

Bytes can now be written with an explicit registry type:

key.set_bytes("other", Type::Other(1234), &[1, 2, 3, 4])?;
assert_eq!(key.get_type("other")?, Type::Other(1234));

Values can be read without dictating their type ahead of time:

let value = key.get_value("other")?;
assert_eq!(value.ty(), Type::Other(1234));
assert_eq!(*value, [1, 2, 3, 4]);

Expand strings are directly supported:

key.set_expand_hstring("expand_hstring", h!("value"))?;
assert_eq!(key.get_type("expand_hstring")?, Type::ExpandString);
assert_eq!(key.get_hstring("expand_hstring")?, "value");

Allocation-free queries and updates can be performed using the unsafe "raw" methods:

key.raw_set_bytes(w!("raw"), Type::Other(1234), &[1, 2, 3])?;

let (ty, len) = key.raw_get_info(w!("raw"))?;
assert_eq!(ty, Type::Other(1234));
assert_eq!(len, 3);

let mut bytes = [0; 3];
key.raw_get_bytes(w!("raw"), &mut bytes)?;
assert_eq!(bytes, [1, 2, 3]);

These raw methods are used internally by all of the safe methods and are available if your needs exceed what is offered by the safe methods.

The Value type can now hold any registry value, known or unknown:

let mut value = Value::try_from("expand")?;
value.set_ty(Type::ExpandString);
assert_eq!(value.ty(), Type::ExpandString);
key.set_value("expand", &value)?;
assert_eq!(key.get_type("expand")?, Type::ExpandString);
assert_eq!(key.get_value("expand")?, value);
assert_eq!(key.get_string("expand")?, "expand");

Fixes: #3148

Copy link
Collaborator

@riverar riverar left a comment

Choose a reason for hiding this comment

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

Thanks for the work on this, looks great!

I only have a few concerns regarding the potential confusion around Registry keys containing Registry values--name/data pairs--and the impact this is having on the API design or usability.

crates/libs/registry/src/value.rs Outdated Show resolved Hide resolved
crates/libs/registry/src/value_bytes.rs Outdated Show resolved Hide resolved
crates/tests/registry/tests/bytes.rs Show resolved Hide resolved
crates/tests/registry/tests/values.rs Show resolved Hide resolved
@kennykerr kennykerr changed the title Refactor windows-registry to support Add precise registry types and allocation-free queries and updates Aug 1, 2024
@kennykerr kennykerr merged commit a6b49e9 into master Aug 1, 2024
78 checks passed
@kennykerr kennykerr deleted the registry5 branch August 1, 2024 16:52
@kennykerr kennykerr mentioned this pull request Oct 30, 2024
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.

Add support for setting string values with the REG_EXPAND_SZ type when modifying the registry
2 participants