From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../rust/winreg/examples/map_key_serialization.rs | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 third_party/rust/winreg/examples/map_key_serialization.rs (limited to 'third_party/rust/winreg/examples/map_key_serialization.rs') diff --git a/third_party/rust/winreg/examples/map_key_serialization.rs b/third_party/rust/winreg/examples/map_key_serialization.rs new file mode 100644 index 0000000000..c0be704913 --- /dev/null +++ b/third_party/rust/winreg/examples/map_key_serialization.rs @@ -0,0 +1,57 @@ +// Copyright 2020, Igor Shaula +// Licensed under the MIT License . This file +// may not be copied, modified, or distributed +// except according to those terms. +#[macro_use] +extern crate serde_derive; +extern crate winreg; +use std::collections::HashMap; +use std::error::Error; +use winreg::enums::*; + +#[derive(Debug, Serialize, Deserialize, PartialEq)] +struct Coords { + x: u32, + y: u32, +} + +#[derive(Debug, Serialize, Deserialize, PartialEq)] +struct Size { + w: u32, + h: u32, +} + +#[derive(Debug, Serialize, Deserialize, PartialEq)] +struct Rectangle { + coords: Coords, + size: Size, +} + +fn main() -> Result<(), Box> { + let hkcu = winreg::RegKey::predef(HKEY_CURRENT_USER); + let (key, _disp) = hkcu.create_subkey("Software\\RustEncodeMapKey")?; + let mut v1 = HashMap::new(); + v1.insert( + "first".to_owned(), + Rectangle { + coords: Coords { x: 55, y: 77 }, + size: Size { w: 500, h: 300 }, + }, + ); + v1.insert( + "second".to_owned(), + Rectangle { + coords: Coords { x: 11, y: 22 }, + size: Size { w: 1000, h: 600 }, + }, + ); + + key.encode(&v1)?; + + let v2: HashMap = key.decode()?; + println!("Decoded {:?}", v2); + + println!("Equal to encoded: {:?}", v1 == v2); + Ok(()) +} -- cgit v1.2.3