summaryrefslogtreecommitdiffstats
path: root/third_party/rust/winreg/examples/transactions.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/winreg/examples/transactions.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/winreg/examples/transactions.rs')
-rw-r--r--third_party/rust/winreg/examples/transactions.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/third_party/rust/winreg/examples/transactions.rs b/third_party/rust/winreg/examples/transactions.rs
new file mode 100644
index 0000000000..4cc91b7c9f
--- /dev/null
+++ b/third_party/rust/winreg/examples/transactions.rs
@@ -0,0 +1,35 @@
+// Copyright 2015, 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.
+extern crate winreg;
+use std::io;
+use winreg::enums::*;
+use winreg::transaction::Transaction;
+use winreg::RegKey;
+
+fn main() -> io::Result<()> {
+ let t = Transaction::new()?;
+ let hkcu = RegKey::predef(HKEY_CURRENT_USER);
+ let (key, _disp) = hkcu.create_subkey_transacted("Software\\RustTransaction", &t)?;
+ key.set_value("TestQWORD", &1_234_567_891_011_121_314u64)?;
+ key.set_value("TestDWORD", &1_234_567_890u32)?;
+
+ println!("Commit transaction? [y/N]:");
+ let mut input = String::new();
+ io::stdin().read_line(&mut input)?;
+ input = input.trim_end().to_owned();
+ if input == "y" || input == "Y" {
+ t.commit()?;
+ println!("Transaction committed.");
+ } else {
+ // this is optional, if transaction wasn't committed,
+ // it will be rolled back on disposal
+ t.rollback()?;
+
+ println!("Transaction wasn't committed, it will be rolled back.");
+ }
+
+ Ok(())
+}