From a39755d4d2e89969c1fd17d6aee87dfe6679f925 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Thu, 1 Aug 2024 08:36:45 -0500 Subject: [PATCH] data --- .../registry/src/{value_bytes.rs => data.rs} | 20 +++++++++---------- crates/libs/registry/src/key.rs | 6 +++--- crates/libs/registry/src/lib.rs | 4 ++-- crates/libs/registry/src/value.rs | 16 +++++++-------- crates/libs/registry/src/value_iterator.rs | 12 +++++------ 5 files changed, 29 insertions(+), 29 deletions(-) rename crates/libs/registry/src/{value_bytes.rs => data.rs} (89%) diff --git a/crates/libs/registry/src/value_bytes.rs b/crates/libs/registry/src/data.rs similarity index 89% rename from crates/libs/registry/src/value_bytes.rs rename to crates/libs/registry/src/data.rs index d0f76c694d..fa1660f391 100644 --- a/crates/libs/registry/src/value_bytes.rs +++ b/crates/libs/registry/src/data.rs @@ -1,12 +1,12 @@ use super::*; // Minimal `Vec` replacement providing at least `u16` alignment so that it can be used for wide strings. -pub struct ValueBytes { +pub struct Data { ptr: *mut u8, len: usize, } -impl ValueBytes { +impl Data { // Creates a buffer with the specified length of zero bytes. pub fn new(len: usize) -> Result { unsafe { @@ -69,7 +69,7 @@ impl ValueBytes { } } -impl Drop for ValueBytes { +impl Drop for Data { fn drop(&mut self) { if !self.ptr.is_null() { unsafe { @@ -79,7 +79,7 @@ impl Drop for ValueBytes { } } -impl Deref for ValueBytes { +impl Deref for Data { type Target = [u8]; fn deref(&self) -> &[u8] { @@ -91,7 +91,7 @@ impl Deref for ValueBytes { } } -impl core::ops::DerefMut for ValueBytes { +impl core::ops::DerefMut for Data { fn deref_mut(&mut self) -> &mut [u8] { if self.ptr.is_null() { &mut [] @@ -101,27 +101,27 @@ impl core::ops::DerefMut for ValueBytes { } } -impl Clone for ValueBytes { +impl Clone for Data { fn clone(&self) -> Self { Self::from_slice(self).unwrap() } } -impl PartialEq for ValueBytes { +impl PartialEq for Data { fn eq(&self, other: &Self) -> bool { self.deref() == other.deref() } } -impl Eq for ValueBytes {} +impl Eq for Data {} -impl core::fmt::Debug for ValueBytes { +impl core::fmt::Debug for Data { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { self.deref().fmt(f) } } -impl TryFrom<[u8; N]> for ValueBytes { +impl TryFrom<[u8; N]> for Data { type Error = Error; fn try_from(from: [u8; N]) -> Result { Self::from_slice(&from) diff --git a/crates/libs/registry/src/key.rs b/crates/libs/registry/src/key.rs index 66e62607a8..f6b5191951 100644 --- a/crates/libs/registry/src/key.rs +++ b/crates/libs/registry/src/key.rs @@ -144,9 +144,9 @@ impl Key { pub fn get_value>(&self, name: T) -> Result { let name = pcwstr(name); let (ty, len) = unsafe { self.raw_get_info(name.as_raw())? }; - let mut value = ValueBytes::new(len)?; - unsafe { self.raw_get_bytes(name.as_raw(), &mut value)? }; - Ok(Value { value, ty }) + let mut data = Data::new(len)?; + unsafe { self.raw_get_bytes(name.as_raw(), &mut data)? }; + Ok(Value { data, ty }) } /// Gets the value for the name in the registry key. diff --git a/crates/libs/registry/src/lib.rs b/crates/libs/registry/src/lib.rs index d862b47b5c..6d04f58022 100644 --- a/crates/libs/registry/src/lib.rs +++ b/crates/libs/registry/src/lib.rs @@ -21,8 +21,8 @@ pub use key::Key; mod value; pub use value::Value; -mod value_bytes; -use value_bytes::ValueBytes; +mod data; +use data::Data; mod pcwstr; use pcwstr::*; diff --git a/crates/libs/registry/src/value.rs b/crates/libs/registry/src/value.rs index 742bf991c2..c2b55a06ce 100644 --- a/crates/libs/registry/src/value.rs +++ b/crates/libs/registry/src/value.rs @@ -3,7 +3,7 @@ use super::*; /// A registry value. #[derive(Clone, PartialEq, Eq, Debug)] pub struct Value { - pub(crate) value: ValueBytes, + pub(crate) data: Data, pub(crate) ty: Type, } @@ -23,13 +23,13 @@ impl core::ops::Deref for Value { type Target = [u8]; fn deref(&self) -> &[u8] { - &self.value + &self.data } } impl AsRef<[u8]> for Value { fn as_ref(&self) -> &[u8] { - &self.value + &self.data } } @@ -37,7 +37,7 @@ impl TryFrom for Value { type Error = Error; fn try_from(from: u32) -> Result { Ok(Self { - value: from.to_le_bytes().try_into()?, + data: from.to_le_bytes().try_into()?, ty: Type::U32, }) } @@ -54,7 +54,7 @@ impl TryFrom for Value { type Error = Error; fn try_from(from: u64) -> Result { Ok(Self { - value: from.to_le_bytes().try_into()?, + data: from.to_le_bytes().try_into()?, ty: Type::U64, }) } @@ -71,7 +71,7 @@ impl TryFrom for String { type Error = Error; fn try_from(from: Value) -> Result { match from.ty { - Type::String | Type::ExpandString => Ok(Self::from_utf16(from.value.as_wide())?), + Type::String | Type::ExpandString => Ok(Self::from_utf16(from.data.as_wide())?), _ => Err(invalid_data()), } } @@ -81,7 +81,7 @@ impl TryFrom<&str> for Value { type Error = Error; fn try_from(from: &str) -> Result { Ok(Self { - value: ValueBytes::from_slice(pcwstr(from).as_bytes())?, + data: Data::from_slice(pcwstr(from).as_bytes())?, ty: Type::String, }) } @@ -92,7 +92,7 @@ impl TryFrom for Vec { fn try_from(from: Value) -> Result { match from.ty { Type::MultiString => Ok(from - .value + .data .as_wide() .split(|c| *c == 0) .map(String::from_utf16_lossy) diff --git a/crates/libs/registry/src/value_iterator.rs b/crates/libs/registry/src/value_iterator.rs index fe801a5fd4..f66f9724c3 100644 --- a/crates/libs/registry/src/value_iterator.rs +++ b/crates/libs/registry/src/value_iterator.rs @@ -5,7 +5,7 @@ pub struct ValueIterator<'a> { key: &'a Key, range: core::ops::Range, name: Vec, - value: ValueBytes, + data: Data, } impl<'a> ValueIterator<'a> { @@ -37,7 +37,7 @@ impl<'a> ValueIterator<'a> { key, range: 0..count as usize, name: vec![0; name_max_len as usize + 1], - value: ValueBytes::new(value_max_len as usize)?, + data: Data::new(value_max_len as usize)?, }) } } @@ -49,7 +49,7 @@ impl<'a> Iterator for ValueIterator<'a> { self.range.next().and_then(|index| { let mut ty = 0; let mut name_len = self.name.len() as u32; - let mut value_len = self.value.len() as u32; + let mut data_len = self.data.len() as u32; let result = unsafe { RegEnumValueW( @@ -59,8 +59,8 @@ impl<'a> Iterator for ValueIterator<'a> { &mut name_len, core::ptr::null(), &mut ty, - self.value.as_mut_ptr(), - &mut value_len, + self.data.as_mut_ptr(), + &mut data_len, ) }; @@ -72,7 +72,7 @@ impl<'a> Iterator for ValueIterator<'a> { Some(( name, Value { - value: ValueBytes::from_slice(&self.value[0..value_len as usize]).unwrap(), + data: Data::from_slice(&self.data[0..data_len as usize]).unwrap(), ty: ty.into(), }, ))