Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Value::coerce_str #11885

Merged
merged 2 commits into from Feb 18, 2024
Merged

Add Value::coerce_str #11885

merged 2 commits into from Feb 18, 2024

Conversation

IanManske
Copy link
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.

Copy link
Member

@sholderbach sholderbach left a comment

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
19 checks passed
@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.

None yet

3 participants