|
3 | 3 | // http://opensource.org/licenses/MIT>. This file
|
4 | 4 | // may not be copied, modified, or distributed
|
5 | 5 | // except according to those terms.
|
| 6 | +#![allow(clippy::needless_doctest_main)] |
6 | 7 |
|
7 | 8 | //! Structure for a registry transaction.
|
8 | 9 | //! Part of `transactions` feature.
|
9 | 10 | //!
|
10 | 11 | //!```no_run
|
11 | 12 | //!use std::io;
|
12 |
| -//!use winreg::RegKey; |
13 | 13 | //!use winreg::enums::*;
|
14 | 14 | //!use winreg::transaction::Transaction;
|
| 15 | +//!use winreg::RegKey; |
15 | 16 | //!
|
16 |
| -//!fn main() { |
17 |
| -//! let t = Transaction::new().unwrap(); |
| 17 | +//!fn main() -> io::Result<()> { |
| 18 | +//! let t = Transaction::new()?; |
18 | 19 | //! let hkcu = RegKey::predef(HKEY_CURRENT_USER);
|
19 |
| -//! let (key, _disp) = hkcu.create_subkey_transacted("Software\\RustTransaction", &t).unwrap(); |
20 |
| -//! key.set_value("TestQWORD", &1234567891011121314u64).unwrap(); |
21 |
| -//! key.set_value("TestDWORD", &1234567890u32).unwrap(); |
| 20 | +//! let (key, _disp) = hkcu.create_subkey_transacted("Software\\RustTransaction", &t)?; |
| 21 | +//! key.set_value("TestQWORD", &1_234_567_891_011_121_314u64)?; |
| 22 | +//! key.set_value("TestDWORD", &1_234_567_890u32)?; |
22 | 23 | //!
|
23 | 24 | //! println!("Commit transaction? [y/N]:");
|
24 | 25 | //! let mut input = String::new();
|
25 |
| -//! io::stdin().read_line(&mut input).unwrap(); |
26 |
| -//! input = input.trim_right().to_owned(); |
| 26 | +//! io::stdin().read_line(&mut input)?; |
| 27 | +//! input = input.trim_end().to_owned(); |
27 | 28 | //! if input == "y" || input == "Y" {
|
28 |
| -//! t.commit().unwrap(); |
| 29 | +//! t.commit()?; |
29 | 30 | //! println!("Transaction committed.");
|
30 |
| -//! } |
31 |
| -//! else { |
| 31 | +//! } else { |
32 | 32 | //! // this is optional, if transaction wasn't committed,
|
33 | 33 | //! // it will be rolled back on disposal
|
34 |
| -//! t.rollback().unwrap(); |
| 34 | +//! t.rollback()?; |
35 | 35 | //!
|
36 | 36 | //! println!("Transaction wasn't committed, it will be rolled back.");
|
37 | 37 | //! }
|
| 38 | +//! |
| 39 | +//! Ok(()) |
38 | 40 | //!}
|
39 | 41 | //!```
|
40 | 42 | use std::io;
|
|
0 commit comments