mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 21:47:46 +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:
@ -6,7 +6,7 @@ pub fn get_matching_brackets_style(default_style: Style, conf: &Config) -> Style
|
||||
const MATCHING_BRACKETS_CONFIG_KEY: &str = "shape_matching_brackets";
|
||||
|
||||
match conf.color_config.get(MATCHING_BRACKETS_CONFIG_KEY) {
|
||||
Some(int_color) => match int_color.coerce_string() {
|
||||
Some(int_color) => match int_color.coerce_str() {
|
||||
Ok(int_color) => merge_styles(default_style, lookup_ansi_color_style(&int_color)),
|
||||
Err(_) => default_style,
|
||||
},
|
||||
|
Reference in New Issue
Block a user