mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-27 13:01:29 +00:00
Add eyre::Ok
(#91)
This change introduces the function eyre::Ok(), a backport of the convenience function anyhow::Ok() which avoids a lengthy turbofish when producing an Ok(()).
This commit is contained in:
parent
a795c97a2b
commit
da84e8c624
@ -709,7 +709,7 @@ pub trait EyreHandler: core::any::Any + Send + Sync {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Result::Ok(())
|
||||
}
|
||||
|
||||
/// Store the location of the caller who constructed this error report
|
||||
@ -831,7 +831,7 @@ impl EyreHandler for DefaultHandler {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Result::Ok(())
|
||||
}
|
||||
|
||||
#[cfg(track_caller)]
|
||||
@ -1193,6 +1193,29 @@ pub trait ContextCompat<T>: context::private::Sealed {
|
||||
F: FnOnce() -> D;
|
||||
}
|
||||
|
||||
/// Equivalent to Ok::<_, eyre::Error>(value).
|
||||
///
|
||||
/// This simplifies creation of an eyre::Result in places where type inference
|
||||
/// cannot deduce the `E` type of the result — without needing to write
|
||||
/// `Ok::<_, eyre::Error>(value)`.
|
||||
///
|
||||
/// One might think that `eyre::Result::Ok(value)` would work in such cases
|
||||
/// but it does not.
|
||||
///
|
||||
/// ```console
|
||||
/// error[E0282]: type annotations needed for `std::result::Result<i32, E>`
|
||||
/// --> src/main.rs:11:13
|
||||
/// |
|
||||
/// 11 | let _ = eyre::Result::Ok(1);
|
||||
/// | - ^^^^^^^^^^^^^^^^ cannot infer type for type parameter `E` declared on the enum `Result`
|
||||
/// | |
|
||||
/// | consider giving this pattern the explicit type `std::result::Result<i32, E>`, where the type parameter `E` is specified
|
||||
/// ```
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Ok<T>(t: T) -> Result<T> {
|
||||
Result::Ok(t)
|
||||
}
|
||||
|
||||
// Not public API. Referenced by macro-generated code.
|
||||
#[doc(hidden)]
|
||||
pub mod private {
|
||||
|
Loading…
x
Reference in New Issue
Block a user