-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy default generic types from source #282
Comments
This is likely because of this line; we use the If someone can submit a PR with it and some tests, then I'll be happy to review it - otherwise, I'll take a look when I'm next able. |
@ColonelThirtyTwo I tried changing that line, and successfully got the defaults to emit. However, I'd have expected the change to make the following code work, and it doesn't: #[derive(Debug, PartialEq, Default, Builder, Clone)]
pub struct GenericWithDefault<T = usize> {
#[builder(default, setter(strip_option))]
lorem: Option<T>,
}
#[test]
fn generic_builder_with_defaults() {
let x = GenericWithDefaultBuilder::default();
let y = x.build().unwrap();
assert_eq!(y, GenericWithDefault { lorem: None });
} The compiler says it cannot figure out the type of |
I'm not sure what you'd like me to test without seeing the code that you changed. My particular use case is more along the lines of: #[derive(Builder)]
#[builder(pattern = "owned")]
pub struct Options<Error = std::io::Error> {
pub on_error: Box<dyn FnMut(Error)>;
} Ideally error would default to |
It's on the branch generics |
@ColonelThirtyTwo did the branch fix your issue? |
Since the proposal in this issue doesn't fix the problem described in the issue and there hasn't been any activity in 4 months, I'm going to close this as Not Pompleted. |
Example code:
The derived
FooBuilder
has a single generic type<T>
likeFoo
, but it does not copy the default typeu32
fromFoo
- it must be specified manually or inferred. It would be convenient if the builder copied the default type.The text was updated successfully, but these errors were encountered: