forked from extern/nushell
Add Value::coerce_str
(#11885)
# Description Following #11851, this PR adds one final conversion function for `Value`. `Value::coerce_str` takes a `&Value` and converts it to a `Cow<str>`, creating an owned `String` for types that needed converting. Otherwise, it returns a borrowed `str` for `String` and `Binary` `Value`s which avoids a clone/allocation. Where possible, `coerce_str` and `coerce_into_string` should be used instead of `coerce_string`, since `coerce_string` always allocates a new `String`.
This commit is contained in:
@@ -738,9 +738,9 @@ fn heavy_lifting(code: Value, escape: bool, osc: bool, call: &Call) -> Result<St
|
||||
});
|
||||
}
|
||||
let code_string = if param_is_string {
|
||||
code.coerce_string().expect("error getting code as string")
|
||||
code.coerce_str().expect("error getting code as string")
|
||||
} else {
|
||||
"".to_string()
|
||||
"".into()
|
||||
};
|
||||
let param_is_valid_string = param_is_string && !code_string.is_empty();
|
||||
if (escape || osc) && (param_is_valid_string) {
|
||||
|
Reference in New Issue
Block a user