mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 23:49:44 +01:00
Refactor PluginCustomValue::render_to_base_value_in
(#12244)
# Description Changed to use `Value::recurse_mut` like the other functions. # User-Facing Changes None # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting
This commit is contained in:
parent
dcf2e8ce9a
commit
c810f5e3da
@ -370,49 +370,21 @@ impl PluginCustomValue {
|
||||
|
||||
/// Render any custom values in the `Value` using `to_base_value()`
|
||||
pub(crate) fn render_to_base_value_in(value: &mut Value) -> Result<(), ShellError> {
|
||||
value.recurse_mut(&mut |value| {
|
||||
let span = value.span();
|
||||
match value {
|
||||
Value::CustomValue { ref val, .. } => {
|
||||
*value = val.to_base_value(span)?;
|
||||
Ok(())
|
||||
}
|
||||
// Any values that can contain other values need to be handled recursively
|
||||
Value::Range { ref mut val, .. } => {
|
||||
Self::render_to_base_value_in(&mut val.from)?;
|
||||
Self::render_to_base_value_in(&mut val.to)?;
|
||||
Self::render_to_base_value_in(&mut val.incr)
|
||||
}
|
||||
Value::Record { ref mut val, .. } => val
|
||||
.iter_mut()
|
||||
.try_for_each(|(_, rec_value)| Self::render_to_base_value_in(rec_value)),
|
||||
Value::List { ref mut vals, .. } => {
|
||||
vals.iter_mut().try_for_each(Self::render_to_base_value_in)
|
||||
}
|
||||
Value::Closure { ref mut val, .. } => val
|
||||
.captures
|
||||
.iter_mut()
|
||||
.map(|(_, captured_value)| captured_value)
|
||||
.try_for_each(Self::render_to_base_value_in),
|
||||
// All of these don't contain other values
|
||||
Value::Bool { .. }
|
||||
| Value::Int { .. }
|
||||
| Value::Float { .. }
|
||||
| Value::Filesize { .. }
|
||||
| Value::Duration { .. }
|
||||
| Value::Date { .. }
|
||||
| Value::String { .. }
|
||||
| Value::Glob { .. }
|
||||
| Value::Block { .. }
|
||||
| Value::Nothing { .. }
|
||||
| Value::Error { .. }
|
||||
| Value::Binary { .. }
|
||||
| Value::CellPath { .. } => Ok(()),
|
||||
// Collect any lazy records that exist and try again
|
||||
Value::LazyRecord { val, .. } => {
|
||||
// Collect LazyRecord before proceeding
|
||||
Value::LazyRecord { ref val, .. } => {
|
||||
*value = val.collect()?;
|
||||
Self::render_to_base_value_in(value)
|
||||
Ok(())
|
||||
}
|
||||
_ => Ok(()),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user