-
Notifications
You must be signed in to change notification settings - Fork 24
Add String::leak #109
Copy link
Copy link
Closed
Labels
ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)API Change Proposal is accepted (seconded with no objections)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
ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)API Change Proposal is accepted (seconded with no objections)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
When working in a resource-constrained environment (e.g. Webassembly), it can be useful to leak a small number of
String's to avoid cloning later on.However, the existing
Box::leak(string.into_boxed_str())may unecessarily reallocate theString, which is presumably whyVec::<u8>::leakexists.Motivation, use-cases
For example, the following code leaks a
Stringwithout reallocation.Solution sketches
*note: It may be necessary to bound the allocator's lifetime appropriately, if and when this lands.
Links and related work
As previously emphasized, this change is an extension of
Vec::<u8>::leak.Right now, StackOverflow answers suggest using
Box::leak(string.into_boxed_str()), which shrinks the string to fit, possibly causing unnecessary reallocation.I previously submitted this as an RFC but that was deemed overkill.
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.