#Converting &str into String
7 messages · Page 1 of 1 (latest)
for me: .to_owned()
these are all semantically different functions:
to_ownedis for conversion of borrowed types to owned types where both the borrowed and owned type are differentto_stringis for invocation of theDisplayimplementation to be shown to the userintois for infallible conversion of data from one type to another
For context, I have a dependencies.txt file where each line is a dependency.
let dependencies =
fs::read_to_string(
format!("{}/dependencies.txt", path)
)?.split("\n").map(|it: &str| it.to_string()).collect();
this is how i parsed it
semantically, to_owned makes the most sense here as it is meant to somehow take ownership of the strings via clone