summaryrefslogtreecommitdiffstats
path: root/third_party/rust/winreg/examples/map_key_serialization.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/winreg/examples/map_key_serialization.rs
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/winreg/examples/map_key_serialization.rs')
-rw-r--r--third_party/rust/winreg/examples/map_key_serialization.rs57
1 files changed, 57 insertions, 0 deletions
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 <LICENSE or
+// http://opensource.org/licenses/MIT>. 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<dyn Error>> {
+ 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<String, Rectangle> = key.decode()?;
+ println!("Decoded {:?}", v2);
+
+ println!("Equal to encoded: {:?}", v1 == v2);
+ Ok(())
+}