Skip to content

Commit 049035f

Browse files
committed
Update the transaction example in the docs
1 parent 5baac5d commit 049035f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/transaction.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,40 @@
33
// http://opensource.org/licenses/MIT>. This file
44
// may not be copied, modified, or distributed
55
// except according to those terms.
6+
#![allow(clippy::needless_doctest_main)]
67

78
//! Structure for a registry transaction.
89
//! Part of `transactions` feature.
910
//!
1011
//!```no_run
1112
//!use std::io;
12-
//!use winreg::RegKey;
1313
//!use winreg::enums::*;
1414
//!use winreg::transaction::Transaction;
15+
//!use winreg::RegKey;
1516
//!
16-
//!fn main() {
17-
//! let t = Transaction::new().unwrap();
17+
//!fn main() -> io::Result<()> {
18+
//! let t = Transaction::new()?;
1819
//! 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)?;
2223
//!
2324
//! println!("Commit transaction? [y/N]:");
2425
//! 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();
2728
//! if input == "y" || input == "Y" {
28-
//! t.commit().unwrap();
29+
//! t.commit()?;
2930
//! println!("Transaction committed.");
30-
//! }
31-
//! else {
31+
//! } else {
3232
//! // this is optional, if transaction wasn't committed,
3333
//! // it will be rolled back on disposal
34-
//! t.rollback().unwrap();
34+
//! t.rollback()?;
3535
//!
3636
//! println!("Transaction wasn't committed, it will be rolled back.");
3737
//! }
38+
//!
39+
//! Ok(())
3840
//!}
3941
//!```
4042
use std::io;

0 commit comments

Comments
 (0)