Fix ModeParseError message

This commit is contained in:
Jeong YunWon 2023-02-22 16:52:40 +09:00
parent aed03c5209
commit 019faeac24
2 changed files with 6 additions and 10 deletions

View file

@ -15,18 +15,16 @@ impl std::str::FromStr for Mode {
"exec" => Ok(Mode::Exec),
"eval" => Ok(Mode::Eval),
"single" => Ok(Mode::Single),
_ => Err(ModeParseError { _priv: () }),
_ => Err(ModeParseError(())),
}
}
}
#[derive(Debug)]
pub struct ModeParseError {
_priv: (),
}
pub struct ModeParseError(());
impl std::fmt::Display for ModeParseError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, r#"mode should be "exec", "eval", or "single""#)
write!(f, r#"mode must be "exec", "eval", or "single""#)
}
}

View file

@ -39,19 +39,17 @@ impl std::str::FromStr for Mode {
match s {
"exec" | "single" => Ok(Mode::Module),
"eval" => Ok(Mode::Expression),
_ => Err(ModeParseError { _priv: () }),
_ => Err(ModeParseError(())),
}
}
}
/// Returned when a given mode is not valid.
#[derive(Debug)]
pub struct ModeParseError {
_priv: (),
}
pub struct ModeParseError(());
impl std::fmt::Display for ModeParseError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, r#"mode should be "exec", "eval", or "single""#)
write!(f, r#"mode must be "exec", "eval", or "single""#)
}
}