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:
Ian Manske
2024-02-18 16:47:10 +00:00
committed by GitHub
parent fb4251aba7
commit 68fcd71898
34 changed files with 115 additions and 83 deletions

View File

@ -89,7 +89,7 @@ fn process(
new_table_name
);
for (column_name, column_datatype) in record {
match column_datatype.coerce_string()?.as_str() {
match column_datatype.coerce_str()?.as_ref() {
"int" => {
create_stmt.push_str(&format!("{} INTEGER, ", column_name));
}