L5KQKEPFTGP2RH5PC6UIQQUKZFNKL7SIHEBIZ4WZHTYXGIBQHFYAC
7B4X77QUU6FEO7YBDMTGJGUDR3EWVORCIUCOZDH76WHZFQ6C2CUAC
JZK5OKKPI672GJNZPKKC3T35E6CUHBLT62YHCKMODOYDLVHU6BUQC
CITEDKPB6MKVZUEYEDE5ZKTNVY35HCOAXKDPYG7YLLEOVFNMSRXQC
4WK6FVX6HW5QUQOJ7K6MCHGXZJ4WCP5BFHWKXEGIH4ANR42SRD7QC
KQXMNV3RMRPSJCQVW4I2HSCFJQ6ZDRLNMJOTQI4MODB6UYA3ONQQC
7JZIPWVKXY3QA5QMTP24WPR7KKMMVXIHAQ4EGHNGCE7H4CRKROCAC
RTVLSOCCLZMZRJZXRIX5RHJMAFJO4XK573NXTBZVBEJSUBJPY5ZQC
UM7DFUYLW4HSMBUDZY3R6ZNJRSX2E75C4DYV3MJAU57EUCGE6JLAC
BZSTVYDVHJA3ZMCM3YTU4U5JKJC2JVUDM5APSBIGMSS54J2C4WKQC
#[cfg(test)]
mod test {
use super::*;
#[test]
fn anyhow() {
let error1 = anyhow!("This {}", "works");
let error2 = anyhow!("This works");
assert_eq!(error1.to_string(), error2.to_string());
}
#[test]
fn bail() {
let f = || -> Result<()> { bail!("This {}", "works") };
let error1 = f().err().unwrap();
let f = || -> Result<()> { bail!("This works") };
let error2 = f().err().unwrap();
assert_eq!(error1.to_string(), error2.to_string());
}
#[test]
fn ensure() {
let f = || {
ensure!(1 + 1 == 2, "This is correct");
Ok(())
};
assert!(f().is_ok());
let v = 1;
let f = || {
ensure!(v + v == 2, "This is correct, v: {}", v);
Ok(())
};
assert!(f().is_ok());
let f = || {
ensure!(v + v == 1, "This is not correct, v: {}", v);
Ok(())
};
assert!(f().is_err());
}
}
}
#[test]
fn test_ensure() {
let f = || {
ensure!(1 + 1 == 2, "This is correct");
Ok(())
};
assert!(f().is_ok());
let v = 1;
let f = || {
ensure!(v + v == 2, "This is correct, v: {}", v);
Ok(())
};
assert!(f().is_ok());
let f = || {
ensure!(v + v == 1, "This is not correct, v: {}", v);
Ok(())
};
assert!(f().is_err());