-
Notifications
You must be signed in to change notification settings - Fork 24
Add NonZeroXxx::from_mut #129
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
Add a function to convert a
&mut xxxto&mut NonZeroXxx.Motivation, use-cases
My project requires working on a
&mut NonZeroU32(because onlyNonZeroU32implements a certain trait I want to use), but the value actually came from a&mut u32somewhere deep inside my data structures, so it would be inconvenient to create a separateNonZeroU32and proxy back the result later on.Solution sketches
For
n: &mut i32, if*n != 0is currently true, and we provide the aforementioned function to map this reference into a&mut NonZeroI32, since the originalncannot be dereferenced without dropping the new&mut NonZeroI32, it is safe to work with the&mut NonZeroI32directly.Links and related work
As this change is very simple, I have already implemented it in a libcore patch: rust-lang/rust#103730
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.