Open
Description
&str
and &[u8]
seems to work by internal magic but it is hard to implement ToOwned
for user composite types. Consider:
struct Foo<'a> {
foo: &'a str,
bar: &'a str,
foobar: &'a str
}
struct FooBuf {
foo: String,
bar: String,
foobar: String
}
It is not possible to mark that FooBuf
is an owned version of Foo
as it would require implementing Borrow
for FooBuf
. However it is not possible to implement fn borrow(&FooBuf) -> &Foo
as we don't have anywhere we can store Foo
. Built-in types workaround it by handling &str
and similar types separately from &T
and packing the actual structure there.
(I know too little about type system to create any RFR which would fix it)