-
Notifications
You must be signed in to change notification settings - Fork 24
str::from_raw_parts #167
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
Add the
str::from_raw_partsandstr::from_raw_parts_mutapisProblem statement
Creating a
strfrom raw parts is a fairly boilerplate filled task.Motivation, use-cases
Often in unsafe or FFI-related code users end up creating strings from their constituent parts, pointers and lengths. However, as of now there's no direct way to do this for
str, instead the user must first create a byte slice and then create a string slice from said byte slice, requiring the user to write more code than they really should have to. This proposal turns the pattern ofinto a simple
str::from_raw_parts(ptr, len)call.Solution sketches
Instead of putting the functions within the
strmodule, they could be methods onstritself to keep the user from having to import thestrmodule or fully qualifyingcore::str::from_raw_partswherever they need to use the function.Links and related work