Skip to content

Commit

Permalink
Merge branch 'winapi'. Bump version to 0.53.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gentoo90 committed Jan 8, 2025
2 parents 1c56127 + cb06180 commit 6d6f35b
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 50 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ jobs:
with:
command: update
args: --package windows_x86_64_msvc:0.48.5 --precise 0.48.5
- name: Restrict libc version
if: matrix.restrict_deps_versions
uses: actions-rs/cargo@v1
with:
command: update
args: --package libc --precise 0.2.164
- name: Restrict num-traits version
if: matrix.restrict_deps_versions
uses: actions-rs/cargo@v1
with:
command: update
args: --package num-traits --precise 0.2.18
- name: Check formatting
if: matrix.lint
uses: actions-rs/cargo@v1
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.15.0, 0.53.0
* Don't stop deserialization of `Any` due to `REG_NONE` (pullrequest [#67](https://github.com/gentoo90/winreg-rs/pull/67), fixes [#66](https://github.com/gentoo90/winreg-rs/issues/66))
* Implement (de)serialization of `Option` ([#56](https://github.com/gentoo90/winreg-rs/issues/56))
* Add `RegKey` methods for creating/opening subkeys with custom options ([#65](https://github.com/gentoo90/winreg-rs/pull/65))

## 0.52.0
* Breaking change: `.commit()` and `.rollback()` now consume the transaction ([#62](https://github.com/gentoo90/winreg-rs/issues/62))
* Add `RegKey::rename_subkey()` method ([#58](https://github.com/gentoo90/winreg-rs/issues/58))
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "winreg"
edition = "2018"
version = "0.52.0"
version = "0.53.0"
authors = ["Igor Shaula <gentoo90@gmail.com>"]
license = "MIT"
description = "Rust bindings to MS Windows Registry API"
Expand All @@ -13,7 +13,7 @@ categories = ["api-bindings", "os::windows-apis"]

[dependencies]
cfg-if = "1.0"
windows-sys = {version = "0.48.0", features = [
windows-sys = {version = "0.48", features = [
"Win32_Foundation",
"Win32_System_Time",
"Win32_System_Registry",
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Current features:
* `u64` <=> `REG_QWORD`
* Iteration through key names and through values
* Transactions
* Transacted serialization of rust types into/from registry (only primitives, structures and maps for now)
* Transacted serialization of rust types into/from registry (only primitives, `Option`s, structures and maps for now)

## Usage

Expand All @@ -36,7 +36,7 @@ Current features:
```toml
# Cargo.toml
[dependencies]
winreg = "0.52"
winreg = "0.53"
```

```rust
Expand Down Expand Up @@ -138,7 +138,7 @@ fn main() -> io::Result<()> {
```toml
# Cargo.toml
[dependencies]
winreg = { version = "0.52", features = ["transactions"] }
winreg = { version = "0.53", features = ["transactions"] }
```

```rust
Expand Down Expand Up @@ -179,7 +179,7 @@ fn main() -> io::Result<()> {
```toml
# Cargo.toml
[dependencies]
winreg = { version = "0.52", features = ["serialization-serde"] }
winreg = { version = "0.53", features = ["serialization-serde"] }
serde = "1"
serde_derive = "1"
```
Expand All @@ -204,7 +204,7 @@ struct Size {

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Rectangle {
coords: Coords,
coords: Option<Coords>,
size: Size,
}

Expand All @@ -219,6 +219,7 @@ struct Test {
t_struct: Rectangle,
t_map: HashMap<String, u32>,
t_string: String,
t_optional_string: Option<String>,
#[serde(rename = "")] // empty name becomes the (Default) value in the registry
t_char: char,
t_i8: i8,
Expand Down Expand Up @@ -248,11 +249,12 @@ fn main() -> Result<(), Box<dyn Error>> {
t_u64: 123_456_789_101_112,
t_usize: 1_234_567_891,
t_struct: Rectangle {
coords: Coords { x: 55, y: 77 },
coords: Some(Coords { x: 55, y: 77 }),
size: Size { w: 500, h: 300 },
},
t_map: map,
t_string: "test 123!".to_owned(),
t_optional_string: Some("test 456!".to_owned()),
t_char: 'a',
t_i8: -123,
t_i16: -2049,
Expand Down
6 changes: 3 additions & 3 deletions examples/map_key_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Size {

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Rectangle {
coords: Coords,
coords: Option<Coords>,
size: Size,
}

Expand All @@ -33,14 +33,14 @@ fn main() -> Result<(), Box<dyn Error>> {
v1.insert(
"first".to_owned(),
Rectangle {
coords: Coords { x: 55, y: 77 },
coords: Some(Coords { x: 55, y: 77 }),
size: Size { w: 500, h: 300 },
},
);
v1.insert(
"second".to_owned(),
Rectangle {
coords: Coords { x: 11, y: 22 },
coords: None,
size: Size { w: 1000, h: 600 },
},
);
Expand Down
6 changes: 4 additions & 2 deletions examples/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Size {

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Rectangle {
coords: Coords,
coords: Option<Coords>,
size: Size,
}

Expand All @@ -37,6 +37,7 @@ struct Test {
t_struct: Rectangle,
t_map: HashMap<String, u32>,
t_string: String,
t_optional_string: Option<String>,
#[serde(with = "serde_bytes")]
t_bytes: Vec<u8>,
#[serde(rename = "")] // empty name becomes the (Default) value in the registry
Expand Down Expand Up @@ -68,11 +69,12 @@ fn main() -> Result<(), Box<dyn Error>> {
t_u64: 123_456_789_101_112,
t_usize: 1_234_567_891,
t_struct: Rectangle {
coords: Coords { x: 55, y: 77 },
coords: Some(Coords { x: 55, y: 77 }),
size: Size { w: 500, h: 300 },
},
t_map: map,
t_string: "test 123!".to_owned(),
t_optional_string: Some("test 456!".to_owned()),
t_bytes: vec![0xDE, 0xAD, 0xBE, 0xEF],
t_char: 'a',
t_i8: -123,
Expand Down
4 changes: 2 additions & 2 deletions examples/transacted_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Size {

#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Rectangle {
coords: Coords,
coords: Option<Coords>,
size: Size,
}

Expand Down Expand Up @@ -70,7 +70,7 @@ fn main() -> Result<(), Box<dyn Error>> {
t_u64: 123_456_789_101_112,
t_usize: 1_234_567_891,
t_struct: Rectangle {
coords: Coords { x: 55, y: 77 },
coords: Some(Coords { x: 55, y: 77 }),
size: Size { w: 500, h: 300 },
},
t_map: map,
Expand Down
5 changes: 1 addition & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ macro_rules! werr {
}

pub(crate) fn to_utf16<P: AsRef<OsStr>>(s: P) -> Vec<u16> {
s.as_ref()
.encode_wide()
.chain(Some(0).into_iter())
.collect()
s.as_ref().encode_wide().chain(Some(0)).collect()
}

pub(crate) fn v16_to_v8(v: &[u16]) -> Vec<u8> {
Expand Down
28 changes: 22 additions & 6 deletions src/decoder/serialization_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// may not be copied, modified, or distributed
// except according to those terms.
use super::{DecodeResult, Decoder, DecoderCursor, DecoderError, DECODER_SAM};
use crate::types::FromRegValue;
use crate::{types::FromRegValue, RegValue};
use serde::de::*;
use std::fmt;

Expand All @@ -14,7 +14,7 @@ impl Error for DecoderError {
}
}

impl<'de, 'a> Deserializer<'de> for &'a mut Decoder {
impl<'de> Deserializer<'de> for &mut Decoder {
type Error = DecoderError;
fn deserialize_any<V>(self, visitor: V) -> DecodeResult<V::Value>
where
Expand All @@ -36,7 +36,11 @@ impl<'de, 'a> Deserializer<'de> for &'a mut Decoder {
REG_DWORD => visitor.visit_u32(u32::from_reg_value(&v)?),
REG_QWORD => visitor.visit_u64(u64::from_reg_value(&v)?),
REG_BINARY => visitor.visit_byte_buf(v.bytes),
_ => no_impl!("value type deserialization not implemented"),
REG_NONE => visitor.visit_none(),
_ => no_impl!(format!(
"value type deserialization not implemented {:?}",
v.vtype
)),
}
}
_ => no_impl!("deserialize_any"),
Expand Down Expand Up @@ -175,9 +179,21 @@ impl<'de, 'a> Deserializer<'de> for &'a mut Decoder {
let v = {
use super::DecoderCursor::*;
match self.cursor {
FieldVal(_, ref name) => {
self.key.get_raw_value(name).map_err(DecoderError::IoError)
}
Start => return visitor.visit_some(&mut *self),
FieldVal(index, ref name) => self
.key
.get_raw_value(name)
.map_err(DecoderError::IoError)
.and_then(|v| match v {
RegValue {
vtype: crate::enums::RegType::REG_NONE,
..
} => {
self.cursor = DecoderCursor::Field(index + 1);
Err(DecoderError::DeserializerError("Found REG_NONE".to_owned()))
}
val => Ok(val),
}),
_ => Err(DecoderError::DeserializerError("Nothing found".to_owned())),
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Encoder<&Transaction> {
key: &RegKey,
tr: &'a Transaction,
) -> EncodeResult<Encoder<&'a Transaction>> {
key.open_subkey_transacted_with_flags("", &tr, ENCODER_SAM)
key.open_subkey_transacted_with_flags("", tr, ENCODER_SAM)
.map(|k| Encoder::new_transacted(k, tr))
.map_err(EncoderError::IoError)
}
Expand Down
17 changes: 10 additions & 7 deletions src/encoder/serialization_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,14 @@ impl<'a, Tr: AsRef<Transaction>> Serializer for &'a mut Encoder<Tr> {
}

fn serialize_none(self) -> EncodeResult<Self::Ok> {
no_impl!("serialize_none")
match mem::replace(&mut self.state, Start) {
NextKey(..) => Ok(()),
Start => Err(EncoderError::NoFieldName),
}
}

fn serialize_some<T: ?Sized + Serialize>(self, _value: &T) -> EncodeResult<Self::Ok> {
no_impl!("serialize_some")
fn serialize_some<T: ?Sized + Serialize>(self, value: &T) -> EncodeResult<Self::Ok> {
value.serialize(self)
}

fn serialize_unit(self) -> EncodeResult<Self::Ok> {
Expand Down Expand Up @@ -455,9 +458,9 @@ impl serde::Serializer for MapKeySerializer {
Err(EncoderError::KeyMustBeAString)
}

fn collect_str<T: ?Sized>(self, value: &T) -> EncodeResult<String>
fn collect_str<T>(self, value: &T) -> EncodeResult<String>
where
T: fmt::Display,
T: fmt::Display + ?Sized,
{
Ok(value.to_string())
}
Expand All @@ -468,7 +471,7 @@ pub struct StructMapEncoder<'a, Tr: AsRef<Transaction>> {
is_root: bool,
}

impl<'a, Tr: AsRef<Transaction>> SerializeStruct for StructMapEncoder<'a, Tr> {
impl<Tr: AsRef<Transaction>> SerializeStruct for StructMapEncoder<'_, Tr> {
type Ok = ();
type Error = EncoderError;

Expand All @@ -489,7 +492,7 @@ impl<'a, Tr: AsRef<Transaction>> SerializeStruct for StructMapEncoder<'a, Tr> {
}
}

impl<'a, Tr: AsRef<Transaction>> SerializeMap for StructMapEncoder<'a, Tr> {
impl<Tr: AsRef<Transaction>> SerializeMap for StructMapEncoder<'_, Tr> {
type Ok = ();
type Error = EncoderError;

Expand Down
4 changes: 3 additions & 1 deletion src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub use windows_sys::Win32::System::Registry::{
HKEY_DYN_DATA, HKEY_LOCAL_MACHINE, HKEY_PERFORMANCE_DATA, HKEY_PERFORMANCE_NLSTEXT,
HKEY_PERFORMANCE_TEXT, HKEY_USERS, KEY_ALL_ACCESS, KEY_CREATE_LINK, KEY_CREATE_SUB_KEY,
KEY_ENUMERATE_SUB_KEYS, KEY_EXECUTE, KEY_NOTIFY, KEY_QUERY_VALUE, KEY_READ, KEY_SET_VALUE,
KEY_WOW64_32KEY, KEY_WOW64_64KEY, KEY_WOW64_RES, KEY_WRITE, REG_PROCESS_APPKEY,
KEY_WOW64_32KEY, KEY_WOW64_64KEY, KEY_WOW64_RES, KEY_WRITE, REG_OPTION_BACKUP_RESTORE,
REG_OPTION_CREATE_LINK, REG_OPTION_DONT_VIRTUALIZE, REG_OPTION_NON_VOLATILE,
REG_OPTION_OPEN_LINK, REG_OPTION_RESERVED, REG_OPTION_VOLATILE, REG_PROCESS_APPKEY,
};

macro_rules! winapi_enum{
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//!```toml,ignore
//!# Cargo.toml
//![dependencies]
//!winreg = "0.52"
//!winreg = "0.53"
//!```
//!
//!```no_run
Expand Down
Loading

0 comments on commit 6d6f35b

Please sign in to comment.