2020-09-08 18:37:14 -05:00
|
|
|
#![warn(clippy::map_err_ignore)]
|
2020-11-17 10:01:22 -06:00
|
|
|
#![allow(clippy::unnecessary_wraps)]
|
2020-09-01 15:59:37 -05:00
|
|
|
use std::convert::TryFrom;
|
|
|
|
use std::error::Error;
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum Errors {
|
|
|
|
Ignored,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Error for Errors {}
|
|
|
|
|
|
|
|
impl fmt::Display for Errors {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "Error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<(), Errors> {
|
|
|
|
let x = u32::try_from(-123_i32);
|
|
|
|
|
|
|
|
println!("{:?}", x.map_err(|_| Errors::Ignored));
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|