Debian Codegraph @

third_party/rust/winreg/examples/transactions.rs

raw
1 // Copyright 2015, Igor Shaula
2 // Licensed under the MIT License <LICENSE or
3 // http://opensource.org/licenses/MIT>. This file
4 // may not be copied, modified, or distributed
5 // except according to those terms.
6 extern crate winreg;
7 use std::io;
8 use winreg::enums::*;
9 use winreg::transaction::Transaction;
10 use winreg::RegKey;
11
12 fn main() -> io::Result<()> {
13 let t = Transaction::new()?;
14 let hkcu = RegKey::predef(HKEY_CURRENT_USER);
15 let (key, _disp) = hkcu.create_subkey_transacted("Software\\RustTransaction", &t)?;
16 key.set_value("TestQWORD", &1_234_567_891_011_121_314u64)?;
17 key.set_value("TestDWORD", &1_234_567_890u32)?;
18
19 println!("Commit transaction? [y/N]:");
20 let mut input = String::new();
21 io::stdin().read_line(&mut input)?;
22 input = input.trim_end().to_owned();
23 if input == "y" || input == "Y" {
24 t.commit()?;
25 println!("Transaction committed.");
26 } else {
27 // this is optional, if transaction wasn't committed,
28 // it will be rolled back on disposal
29 t.rollback()?;
30
31 println!("Transaction wasn't committed, it will be rolled back.");
32 }
33
34 Ok(())
35 }