Unidiomatic use of `Result::and_then` in README
ruifengx opened this issue · 0 comments
ruifengx commented
Currently the code in the README:
fn main() -> ::windows::core::Result<()> {
bootstrap::initialize()
.and_then(|_| {
println!(
"Remaining charge: {}%",
PowerManager::RemainingChargePercent()?
);
Ok(())
})
.and_then(|_| bootstrap::uninitialize())
}
I strongly suggest replacing it with the following:
fn main() -> ::windows::core::Result<()> {
bootstrap::initialize()?;
println!(
"Remaining charge: {}%",
PowerManager::RemainingChargePercent()?,
);
bootstrap::uninitialize()
}
I personally cannot think of any reason preventing the use of the ?
operator, because it is already used in the original example. I would go even further to suggest the following:
fn main() -> ::windows::core::Result<()> {
bootstrap::initialize()?;
let power = PowerManager::RemainingChargePercent()?;
println!("Remaining charge: {power}%");
bootstrap::uninitialize()
}