Say we have:
struct Foo {
string: String
}
impl Foo {
fn new(thing: ?) -> Foo {
let string: String = thing.magic();
Foo { string }
}
}
If thing
is a String
already, I'd like to claim ownership as-is without a clone. If it's some other kind of string-like object, I'd like to to_string()
it (etc.) to produced an owned version. I'm sure there's a Trait or wrapper type in std
for this, I'm just not sure what it is. ToString
doesn't seem right, as that clones the String
if it was already a String
.
Thoughts? Thanks you kindly.