Reduce again the number of match calls (#7815)

- Reduce the number of match calls (see commit messages)
- A few miscellaneous improvements
This commit is contained in:
Hofer-Julian
2023-01-24 12:23:42 +01:00
committed by GitHub
parent 0bb2e47c98
commit 41306aa7e0
49 changed files with 467 additions and 634 deletions

View File

@ -22,15 +22,18 @@ impl CoolCustomValue {
pub fn try_from_value(value: &Value) -> Result<Self, ShellError> {
match value {
Value::CustomValue { val, span } => match val.as_any().downcast_ref::<Self>() {
Some(cool) => Ok(cool.clone()),
None => Err(ShellError::CantConvert(
"cool".into(),
"non-cool".into(),
*span,
None,
)),
},
Value::CustomValue { val, span } => {
if let Some(cool) = val.as_any().downcast_ref::<Self>() {
Ok(cool.clone())
} else {
Err(ShellError::CantConvert(
"cool".into(),
"non-cool".into(),
*span,
None,
))
}
}
x => Err(ShellError::CantConvert(
"cool".into(),
x.get_type().to_string(),