diff options
| author | Botahamec <botahamec@outlook.com> | 2022-10-23 13:39:58 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2022-10-23 13:39:58 -0400 |
| commit | b3a59407812b94a13fd83bf7fec36aac526359a1 (patch) | |
| tree | 27f9bf78f3a7c917bd2fa3db99b25d03881eecef /src/result.rs | |
| parent | f4b5e2afc59a30687a0630504e233ecb63339783 (diff) | |
Updated docs
Diffstat (limited to 'src/result.rs')
| -rw-r--r-- | src/result.rs | 73 |
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>; } |
