mirror of
https://github.com/nushell/nushell.git
synced 2025-01-11 08:48:23 +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()`
|
/// Render any custom values in the `Value` using `to_base_value()`
|
||||||
pub(crate) fn render_to_base_value_in(value: &mut Value) -> Result<(), ShellError> {
|
pub(crate) fn render_to_base_value_in(value: &mut Value) -> Result<(), ShellError> {
|
||||||
let span = value.span();
|
value.recurse_mut(&mut |value| {
|
||||||
match value {
|
let span = value.span();
|
||||||
Value::CustomValue { ref val, .. } => {
|
match value {
|
||||||
*value = val.to_base_value(span)?;
|
Value::CustomValue { ref val, .. } => {
|
||||||
Ok(())
|
*value = val.to_base_value(span)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
// Collect LazyRecord before proceeding
|
||||||
|
Value::LazyRecord { ref val, .. } => {
|
||||||
|
*value = val.collect()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => 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, .. } => {
|
|
||||||
*value = val.collect()?;
|
|
||||||
Self::render_to_base_value_in(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user