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.
Thank you for the awesome crate!
Here is a feature suggestion, that is sorely missed in our projects. It has also been requested twice already (#43 and #62).
#[new(into)]
To make type conversion easier,
#[new(into)]
attribute changes the parameter type toimpl Into<T>
, and populates the field withvalue.into()
. This is useful for containers like strings, accepting aString
or a&str
:It is also useful for wrapping types like
Box<T>
andRc<T>
, without having to wrap at every callsite:#[new(into_iter = "T")]
For iterators/collections,
#[new(into_iter = "T")]
attribute changes the parameter type toimpl IntoIterator<Item = T>
, and populates the field withvalue.into_iter().collect()
. This allows initializing with a variety of types, like[T]
,Option<T>
,Vec<T>
, sets, maps, and even other iterators:About this PR
I split this into three parts to make reviewing easier:
cargo fmt
).README.md
andlib.rs
.Please let me know if I can do anything else.