mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 09:55:42 +02:00
Add functions for each Value
case (#9736)
# Description This PR ensures functions exist to extract and create each and every `Value` case. It also renames `Value::boolean` to `Value::bool` to match `Value::test_bool`, `Value::as_bool`, and `Value::Bool`. Similarly, `Value::as_integer` was renamed to `Value::as_int` to be consistent with `Value::int`, `Value::test_int`, and `Value::Int`. These two renames can be undone if necessary. # User-Facing Changes No user facing changes, but two public functions were renamed which may affect downstream dependents.
This commit is contained in:
@ -89,7 +89,7 @@ fn ends_with(val: &Value, args: &Arguments, span: Span) -> Value {
|
||||
Value::Binary {
|
||||
val,
|
||||
span: val_span,
|
||||
} => Value::boolean(val.ends_with(&args.pattern), *val_span),
|
||||
} => Value::bool(val.ends_with(&args.pattern), *val_span),
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => val.clone(),
|
||||
other => Value::Error {
|
||||
|
@ -98,16 +98,16 @@ impl Command for BytesStartsWith {
|
||||
i += max;
|
||||
|
||||
if i >= arg.pattern.len() {
|
||||
return Ok(Value::boolean(true, span).into_pipeline_data());
|
||||
return Ok(Value::bool(true, span).into_pipeline_data());
|
||||
}
|
||||
} else {
|
||||
return Ok(Value::boolean(false, span).into_pipeline_data());
|
||||
return Ok(Value::bool(false, span).into_pipeline_data());
|
||||
}
|
||||
}
|
||||
|
||||
// We reached the end of the stream and never returned,
|
||||
// the pattern wasn't exhausted so it probably doesn't match
|
||||
Ok(Value::boolean(false, span).into_pipeline_data())
|
||||
Ok(Value::bool(false, span).into_pipeline_data())
|
||||
}
|
||||
_ => operate(
|
||||
starts_with,
|
||||
@ -145,7 +145,7 @@ fn starts_with(val: &Value, args: &Arguments, span: Span) -> Value {
|
||||
Value::Binary {
|
||||
val,
|
||||
span: val_span,
|
||||
} => Value::boolean(val.starts_with(&args.pattern), *val_span),
|
||||
} => Value::bool(val.starts_with(&args.pattern), *val_span),
|
||||
// Propagate errors by explicitly matching them before the final case.
|
||||
Value::Error { .. } => val.clone(),
|
||||
other => Value::Error {
|
||||
|
Reference in New Issue
Block a user