mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-13 09:05:00 +00:00
25 lines
408 B
Rust
25 lines
408 B
Rust
|
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(())
|
||
|
}
|