mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 06:45:59 +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:
@ -9,7 +9,7 @@ pub const CMD_NAME: &str = "from ics";
|
||||
|
||||
pub fn from_ics_call(call: &EvaluatedCall, input: &Value) -> Result<Value, LabeledError> {
|
||||
let span = input.span();
|
||||
let input_string = input.coerce_string()?;
|
||||
let input_string = input.coerce_str()?;
|
||||
let head = call.head;
|
||||
|
||||
let input_string = input_string
|
||||
|
@ -5,7 +5,7 @@ pub const CMD_NAME: &str = "from ini";
|
||||
|
||||
pub fn from_ini_call(call: &EvaluatedCall, input: &Value) -> Result<Value, LabeledError> {
|
||||
let span = input.span();
|
||||
let input_string = input.coerce_string()?;
|
||||
let input_string = input.coerce_str()?;
|
||||
let head = call.head;
|
||||
|
||||
let ini_config: Result<ini::Ini, ini::ParseError> = ini::Ini::load_from_str(&input_string);
|
||||
|
@ -8,7 +8,7 @@ pub const CMD_NAME: &str = "from vcf";
|
||||
|
||||
pub fn from_vcf_call(call: &EvaluatedCall, input: &Value) -> Result<Value, LabeledError> {
|
||||
let span = input.span();
|
||||
let input_string = input.coerce_string()?;
|
||||
let input_string = input.coerce_str()?;
|
||||
let head = call.head;
|
||||
|
||||
let input_string = input_string
|
||||
|
Reference in New Issue
Block a user