You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to add additional generics bounds on field setters?
This would help in cases where setting bounds in the struct definition is annoying (which is most of the time), but the structure only makes sense with specific trait bounds.
In my use-case, I use () as the alternative to a T: SomeTrait, and only implement functionality for T: SomeTrait. The setter is only useful in cases where the T implements some additional traits.
use typed_builder::TypedBuilder;#[derive(TypedBuilder)]structGeneric<T:Default>{// vvv The new syntax could be something like this#[builder(default, setter(strip_option, generic_bounds = Send + Sync))]optional_thing:Option<T>,}structDefaults(*consti32);implDefaultforDefaults{fndefault() -> Self{Self(&0as*consti32)}}fnfoo(){// ERROR: .optional_thing can only be called with T that's Default + Send + SyncGeneric::builder().optional_thing(Defaults::default());}
The text was updated successfully, but these errors were encountered:
Because T doesn't necessarily have to have those bounds - they're only important if they're set.
Consider a bound MyCustomTrait, where T can be either T: MyCustomTrait, or ().
I'll only want to set the Option to Some when T is not (), and it needs to implement the trait.
Is there a way to add additional generics bounds on field setters?
This would help in cases where setting bounds in the
struct
definition is annoying (which is most of the time), but the structure only makes sense with specific trait bounds.In my use-case, I use
()
as the alternative to aT: SomeTrait
, and only implement functionality forT: SomeTrait
. The setter is only useful in cases where theT
implements some additional traits.The text was updated successfully, but these errors were encountered: