summaryrefslogtreecommitdiff
path: root/src/result.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/result.rs')
-rw-r--r--src/result.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/result.rs b/src/result.rs
index 9f1bb89..2b8921c 100644
--- a/src/result.rs
+++ b/src/result.rs
@@ -13,6 +13,44 @@ use sealed::Sealed;
#[cfg(feature = "std")]
pub trait ResultErrorExt<T>: Sealed {
/// Converts `Result<T, E>` to `Result<T, RawUnexpected>`.
+ ///
+ /// # Examples
+ ///
+ /// Basic usage:
+ ///
+ /// ```
+ /// use exun::*;
+ /// use core::fmt::Error;
+ ///
+ /// let res: Result<i32, Error> = Err(Error);
+ /// let res: Result<i32, RawUnexpected> = res.unexpect();
+ /// ```
+ ///
+ /// Use with the try operator
+ ///
+ /// ```
+ /// use exun::*;
+ /// use core::fmt::Error;
+ ///
+ /// fn foo() -> Result<i32, UnexpectedError> {
+ /// let res: Result<i32, Error> = Err(Error);
+ /// Ok(res.unexpect()?)
+ /// }
+ /// ```
+ ///
+ /// Use with the try operator and [`Exun`]
+ ///
+ /// ```
+ /// use exun::*;
+ /// use core::fmt::Error;
+ ///
+ /// fn foo() -> Result<i32, Exun<(), UnexpectedError>> {
+ /// let res: Result<i32, Error> = Err(Error);
+ /// Ok(res.unexpect()?)
+ /// }
+ /// ```
+ ///
+ /// [`Exun`]: `crate::Exun`
#[allow(clippy::missing_errors_doc)]
fn unexpect(self) -> Result<T, RawUnexpected>;
}
@@ -29,6 +67,41 @@ pub trait ResultMsgExt<T>: Sealed {
///
/// This is provided for compatibility with `no_std`. If your type
/// implements [`Error`], then you should prefer that instead.
+ ///
+ /// # Examples
+ ///
+ /// Basic usage:
+ ///
+ /// ```
+ /// use exun::*;
+ ///
+ /// let res: Result<i32, &str> = Err("failure");
+ /// let res: Result<i32, RawUnexpected> = res.unexpect_msg();
+ /// ```
+ ///
+ /// Use with the try operator
+ ///
+ /// ```
+ /// use exun::*;
+ ///
+ /// fn foo() -> Result<i32, UnexpectedError> {
+ /// let res: Result<i32, &str> = Err("failure");
+ /// Ok(res.unexpect_msg()?)
+ /// }
+ /// ```
+ ///
+ /// Use with the try operator and [`Exun`]
+ ///
+ /// ```
+ /// use exun::*;
+ ///
+ /// fn foo() -> Result<i32, Exun<(), UnexpectedError>> {
+ /// let res: Result<i32, &str> = Err("failure");
+ /// Ok(res.unexpect_msg()?)
+ /// }
+ /// ```
+ ///
+ /// [`Exun`]: `crate::Exun`
#[allow(clippy::missing_errors_doc)]
fn unexpect_msg(self) -> Result<T, RawUnexpected>;
}