mirror of
https://github.com/nushell/nushell.git
synced 2025-08-19 04:45:57 +02:00
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:
@@ -325,9 +325,9 @@ pub fn nu_repl() {
|
||||
|
||||
if let Some(cwd) = stack.get_env_var(&engine_state, "PWD") {
|
||||
let path = cwd
|
||||
.coerce_string()
|
||||
.coerce_str()
|
||||
.unwrap_or_else(|err| outcome_err(&engine_state, &err));
|
||||
let _ = std::env::set_current_dir(path);
|
||||
let _ = std::env::set_current_dir(path.as_ref());
|
||||
engine_state.add_env_var("PWD".into(), cwd);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user