I'd love to be able to completely customise the input type for builder methods, for situations where impl Into isn't enough.
For example, if I have a HashSet<T> as a struct field, it would be much nicer to accept an impl IntoIterator<Item = T> then have the buider method do input.into_iter().collect() rather than the builder method accepting impl Into<HashSet<T>> and the user having to do the rest.
Not sure how this could be implemented, there would have to be a way to specify the desired input type, and also perhaps pass in to the macro a function that goes from the input type to the type of the struct field. E.g:
#[builder]
struct ExampleStruct {
#[builder(input_type = impl IntoIterator<Item = u32>, convert_fn = convert)]
example: HashSet<u32>,
}
fn convert(input: impl IntoIterator<Item = u32>) -> HashSet<u32> {
input.into_iter().collect()
}
Or perhaps it could be possible to supply a closure:
#[builder]
struct ExampleStruct {
#[builder(input_type = impl IntoIterator<Item = u32>, convert_fn = |x| x.into_iter().collect())]
example: HashSet<u32>,
}
A note for the community from the maintainers
Please vote on this issue by adding a 👍 reaction to help the maintainers with prioritizing it. You may add a comment describing your real use case related to this issue for us to better understand the problem domain.
I'd love to be able to completely customise the input type for builder methods, for situations where
impl Intoisn't enough.For example, if I have a
HashSet<T>as a struct field, it would be much nicer to accept animpl IntoIterator<Item = T>then have the buider method doinput.into_iter().collect()rather than the builder method acceptingimpl Into<HashSet<T>>and the user having to do the rest.Not sure how this could be implemented, there would have to be a way to specify the desired input type, and also perhaps pass in to the macro a function that goes from the input type to the type of the struct field. E.g:
Or perhaps it could be possible to supply a closure:
A note for the community from the maintainers
Please vote on this issue by adding a 👍 reaction to help the maintainers with prioritizing it. You may add a comment describing your real use case related to this issue for us to better understand the problem domain.