mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 04:39:18 +00:00
boxed traits
This commit is contained in:
parent
5fc192bf5c
commit
302d222e25
@ -10,6 +10,7 @@ use std::error;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
|
type Result<T, E> = std::result::Result<T, Box<dyn E>>;
|
||||||
// TODO: update the return type of `main()` to make this compile.
|
// TODO: update the return type of `main()` to make this compile.
|
||||||
fn main() -> Result<(), ParseIntError> {
|
fn main() -> Result<(), ParseIntError> {
|
||||||
let pretend_user_input = "42";
|
let pretend_user_input = "42";
|
||||||
@ -18,6 +19,17 @@ fn main() -> Result<(), ParseIntError> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// impl From<CreationError> for ParseIntError{
|
||||||
|
// fn from(e: CreationError) -> ParseIntError{
|
||||||
|
// return ParseIntError::CreationError(e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// impl From<ParseIntError> for CreationError{
|
||||||
|
// fn from(e: ParseIntError) -> CreationError{
|
||||||
|
// return CreationError::ParseIntError(e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
// Don't change anything below this line.
|
// Don't change anything below this line.
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
@ -34,7 +46,7 @@ impl PositiveNonzeroInteger {
|
|||||||
match value {
|
match value {
|
||||||
x if x < 0 => Err(CreationError::Negative),
|
x if x < 0 => Err(CreationError::Negative),
|
||||||
x if x == 0 => Err(CreationError::Zero),
|
x if x == 0 => Err(CreationError::Zero),
|
||||||
x => Ok(PositiveNonzeroInteger(x as u64))
|
x => Ok(PositiveNonzeroInteger(x as u64)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user