-
Notifications
You must be signed in to change notification settings - Fork 24
ACP: Move ToOwned and Cow to core. #519
Copy link
Copy link
Closed as not planned
Labels
I-libs-api-nominatedIndicates that an issue has been nominated for discussion during a team meeting.Indicates that an issue has been nominated for discussion during a team meeting.T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard librariesA proposal to add or alter unstable APIs in the standard libraries
Metadata
Metadata
Assignees
Labels
I-libs-api-nominatedIndicates that an issue has been nominated for discussion during a team meeting.Indicates that an issue has been nominated for discussion during a team meeting.T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard librariesA proposal to add or alter unstable APIs in the standard libraries
Type
Fields
Give feedbackNo fields configured for issues without a type.
Proposal
Problem statement
The standard library's
alloccrate defines theToOwnedtrait and theCowtype in theborrowmodule. This module is closely tied to Rust's ownership model, and thecorecrate also defines some facilities in this module (i.e. theBorrowandBorrowMuttraits).Whilst both
ToOwnedandCoware usually used in conjunction with thealloccrate's dynamically-allocated types (such asStringandVec), they do not intrinsically need to be coupled with these types.The issue with having these items in
allocis that it renders it impossible for crates to implementToOwnedfor their own types (without, of course, importing eitherallocorstd). This is despite the fact that it is theoretically possible to define this trait without using any other facilities fromallocorstd(the ownership model, at least, exists no matter the combination of crates used).Motivating examples or use cases
Third-party crates that define their own sense of borrowed vs. owned types would naturally want to implement
ToOwnedfor the borrowed types. But this currently requires importing either of theallocorstdcrates, which may not necessarily be wanted (especially if the crate uses theno_stdattribute).Solution sketch
Move the definitions of
ToOwnedandCowintocore:As the
Cowtype is very closely related toToOwned, I do not see any reason for keeping it separated shouldToOwnedbe moved tocore.Alternatives
Third-party crates could define their own
ToOwnedorCow. But this would be completely redundant as the standard items already exist, albeit in an incompatible context.