Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added methods to get constant references to values on the Valued trait.
- Loading branch information
1 parent
eae8719
commit f34e979
Showing
5 changed files
with
179 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use alloc::string::ToString; | ||
|
||
pub(crate) fn print_info<TNameRet: ToString, TInfoRet: ToString, TName: FnOnce() -> TNameRet, TInfo: FnOnce() -> TInfoRet>(_name: TName, _info: TInfo) { | ||
//eprintln!("--------------------- {} ---------------------\n", (_name()).to_string()); | ||
//eprintln!("{}\n", (_info()).to_string()); | ||
//eprintln!("-------------------------------------------------------------\n"); | ||
} | ||
|
||
pub(crate) trait ExpectElseResult<T, E> { | ||
fn expect_else<TInfoRet: ToString, TInfo: FnOnce(&E) -> TInfoRet>(self, info: TInfo) -> T; | ||
} | ||
|
||
impl<T, E: core::fmt::Debug> ExpectElseResult<T, E> for Result<T, E> { | ||
fn expect_else<TInfoRet: ToString, TInfo: FnOnce(&E) -> TInfoRet>(self, info: TInfo) -> T { | ||
if self.is_ok() { | ||
self.expect("") | ||
} else { | ||
let error_info = match &self { | ||
Err(error) => info(error).to_string(), | ||
_ => { panic!("Unreachable point"); } | ||
}; | ||
self.expect(&error_info) | ||
} | ||
} | ||
} | ||
|
||
|
||
pub(crate) trait ExpectElseOption<T> { | ||
fn expect_else<TInfoRet: ToString, TInfo: FnOnce() -> TInfoRet>(self, info: TInfo) -> T; | ||
} | ||
|
||
impl<T> ExpectElseOption<T> for Option<T> { | ||
fn expect_else<TInfoRet: ToString, TInfo: FnOnce() -> TInfoRet>(self, info: TInfo) -> T { | ||
if self.is_some() { | ||
self.expect("") | ||
} else { | ||
self.expect(&info().to_string()) | ||
} | ||
} | ||
} |