Skip to content
Myr

Merge pull request 2 from EmbarkStudios/bail-single-str

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

authored by David Tolnay · committed by David Tolnay · parents abcb255, 9c6fe32 · Browse files · 1 file+21 added−4 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+21 added−4 removed

  • other:+21 added−4 removed

1 file+21 added−4 removed

modified:src/lib.rs+21 added-4 removed
281 unmodified lines
282/// # }283/// ```284#[macro_export]285macro_rules! bail {286 ($msg:literal $(,)?) => {287 return std::result::Result::Err($crate::anyhow!($msg));288 };286 ($err:expr $(,)?) => {290 return std::result::Result::Err(std::convert::From::from($err));287 return std::result::Result::Err($crate::anyhow!($err));288 };289 ($fmt:expr, $($arg:tt)*) => {290 return std::result::Result::Err($crate::anyhow!($fmt, $($arg)*));291 };
127 unmodified lines
419}420421#[cfg(test)]422mod test {423 use super::*;424425 #[test]426 fn anyhow() {427 let error1 = anyhow!("This {}", "works");428 let error2 = anyhow!("This works");429 assert_eq!(error1.to_string(), error2.to_string());430 }431432 #[test]433 fn bail() {434 let f = || -> Result<()> { bail!("This {}", "works") };435 let error1 = f().err().unwrap();436437 let f = || -> Result<()> { bail!("This works") };438 let error2 = f().err().unwrap();439440 assert_eq!(error1.to_string(), error2.to_string());441 }442443 #[test]444 fn ensure() {445 let f = || {446 ensure!(1 + 1 == 2, "This is correct");447 Ok(())
17 unmodified lines