Skip to content

Add Value::coerce_str - #11885

Merged
sholderbach merged 2 commits into
nushell:mainfrom
IanManske:coerce-str
Feb 18, 2024
Merged

sholderbach merged 2 commits into
nushell:mainfrom
IanManske:coerce-str

Conversation

@IanManske

Copy link
Copy Markdown
Member

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 Values 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.

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call!

@sholderbach
sholderbach merged commit 68fcd71 into nushell:main Feb 18, 2024
@hustcer hustcer added this to the v0.91.0 milestone Feb 19, 2024
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
Following nushell#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`.
kik4444 pushed a commit to kik4444/nushell-fork that referenced this pull request Feb 28, 2024
# Description
Following nushell#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`.
@IanManske
IanManske deleted the coerce-str branch March 26, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants