Skip to content
Myr

Add anyhow::Ok

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Closes #192.

authored by David Tolnay · committed by David Tolnay · parent 21a4e70 · Browse files · 1 file+24 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+24 added−0 removed

  • other:+24 added−0 removed

1 file+24 added−0 removed

modified:src/lib.rs+24 added
600 unmodified lines
601 C: Display + Send + Sync + 'static,602 F: FnOnce() -> C;603}604605/// Equivalent to `Ok::<_, anyhow::Error>(value)`.606///607/// This simplifies creation of an anyhow::Result in places where type inference608/// cannot deduce the `E` type of the result &mdash; without needing to write609/// `Ok::<_, anyhow::Error>(value)`.610///611/// One might think that `anyhow::Result::Ok(value)` would work in such cases612/// but it does not.613///614/// ```console615/// error[E0282]: type annotations needed for `std::result::Result<i32, E>`616/// --> src/main.rs:11:13617/// |618/// 11 | let _ = anyhow::Result::Ok(1);619/// | - ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `E` declared on the enum `Result`620/// | |621/// | consider giving this pattern the explicit type `std::result::Result<i32, E>`, where the type parameter `E` is specified622/// ```623#[doc(hidden)]624#[allow(non_snake_case)]625pub fn Ok<T>(t: T) -> Result<T> {626 Result::Ok(t)627}628629// Not public API. Referenced by macro-generated code.630#[doc(hidden)]631pub mod private {632 use crate::Error;
34 unmodified lines