🚧 Code tweak
This commit is contained in:
parent
0a61270f22
commit
17f266b032
2 changed files with 9 additions and 9 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
mod context;
|
mod context;
|
||||||
pub use context::{AssetsOp, Context, ParamError};
|
pub use context::{AssetsOp, Context, ErrorParam};
|
||||||
pub type FnContextualPath = fn(cx: &Context) -> &str;
|
pub type FnContextualPath = fn(cx: &Context) -> &str;
|
||||||
|
|
||||||
mod definition;
|
mod definition;
|
||||||
|
|
|
||||||
|
|
@ -30,21 +30,21 @@ pub enum AssetsOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ParamError {
|
pub enum ErrorParam {
|
||||||
NotFound,
|
NotFound,
|
||||||
ParseError(String),
|
ParseError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ParamError {
|
impl fmt::Display for ErrorParam {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
ParamError::NotFound => write!(f, "Parameter not found"),
|
ErrorParam::NotFound => write!(f, "Parameter not found"),
|
||||||
ParamError::ParseError(e) => write!(f, "Parse error: {e}"),
|
ErrorParam::ParseError(e) => write!(f, "Parse error: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for ParamError {}
|
impl Error for ErrorParam {}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
|
|
@ -147,11 +147,11 @@ impl Context {
|
||||||
&self.regions
|
&self.regions
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_param<T: FromStr + ToString>(&self, key: &'static str) -> Result<T, ParamError> {
|
pub fn get_param<T: FromStr + ToString>(&self, key: &'static str) -> Result<T, ErrorParam> {
|
||||||
self.params
|
self.params
|
||||||
.get(key)
|
.get(key)
|
||||||
.ok_or(ParamError::NotFound)
|
.ok_or(ErrorParam::NotFound)
|
||||||
.and_then(|v| T::from_str(v).map_err(|_| ParamError::ParseError(v.clone())))
|
.and_then(|v| T::from_str(v).map_err(|_| ErrorParam::ParseError(v.clone())))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context PREPARE.
|
// Context PREPARE.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue