-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-langRelevant to the language teamRelevant to the language team
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)
brunocodutra, inikulin, ratijas, 95th, arnauorriols and 2 more
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-langRelevant to the language teamRelevant to the language team