Add #[try_from(type[, err, err-constructor])]
#430
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.
It is briefly described in the docs and tests so I spare the duplicate information
open the discussion by means of an example.
I felt this is needed when working on an NLP library.
Assume a language has 2 set of characters like below:
The developer, for whatever reason, decides to also make a union set (not to be confused
with the unsafe union type) as written:
This macro makes the latter implementation exactly as described.
The first field returning a valid answer to the
try_from
will beset and used.
This is rather situational but I thought it's a good idea to share it
here even though this is my first contribution and I'm not really good
with the custom utilities and standards of this library and only read the
parts of code concerned with my own use case... so yeah, have it at that.
Regarding the previous behavior, only a slight
compile_fail
situation (tests/compile_fail/try_from/invalid_repr.stderr
) is changed and therest is intact.
I'll be glad to have any suggestions and change requests...
P.S: If not reviewed rapidly, I'll do my best to clean up the code more
and update the docs (as I suspect some comments may be old or misleading as
this was my after-work little patch and I apologize for whatever shortcomings it has).