Feature suggestion to apply into() on non-optional and optional values #4230
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a minimal feature request/suggestion to lessen the boilerplate of dealing with optionals. Consider this convoluted example
instead of requiring the manual constructor
Option::Some(call_with_optional_result()?)
, which to me loses some clarity of expression.It broadens the use of
.into()
to either wrap a non-optional value into its expected optional result or, in the case where there is a clear type conversion such as an upcast (into) or downcast (try_into) between optional types, those cases can be considered as well.Maybe the scope of
into()
is inappropriate for the suggested behavior here. In some languages, perhaps the more natural applications of dealing with optional type conversion is through (functor) maps.N.b. that a type conversion between
Option<A>
toOption<B>
where there existsTryInto<A, B>
, is possible with an.into()
as opposed to a.try_into()
as well, but semantically it may cause more harm than good. Consider this in contrast to what was committed in the PRThis change is