mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
에러 5번 푸는중..
This commit is contained in:
parent
b9022cfd1f
commit
8de108505d
@ -1,7 +1,6 @@
|
||||
// errors4.rs
|
||||
// Make this test pass! Execute `rustlings hint errors4` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
struct PositiveNonzeroInteger(u64);
|
||||
@ -14,7 +13,12 @@ enum CreationError {
|
||||
|
||||
impl PositiveNonzeroInteger {
|
||||
fn new(value: i64) -> Result<PositiveNonzeroInteger, CreationError> {
|
||||
Ok(PositiveNonzeroInteger(value as u64))
|
||||
match value{
|
||||
(value) if value>0 =>Ok(PositiveNonzeroInteger(value as u64)),
|
||||
(value) if value==0=>Err(CreationError::Zero),
|
||||
(value) if value < 0=>Err(CreationError::Negative),
|
||||
_=>Err(panic!("no"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ use std::fmt;
|
||||
use std::num::ParseIntError;
|
||||
|
||||
// TODO: update the return type of `main()` to make this compile.
|
||||
fn main() -> Result<(), ParseIntError> {
|
||||
fn main() -> Result<(), (ParseIntError,CreationError)> {
|
||||
let pretend_user_input = "42";
|
||||
let x: i64 = pretend_user_input.parse()?;
|
||||
println!("output={:?}", PositiveNonzeroInteger::new(x)?);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user