nutype icon indicating copy to clipboard operation
nutype copied to clipboard

Respect `where` clause in generic newtypes

Open greyblake opened this issue 1 year ago β€’ 0 comments

At the moment boundaries can be set only within <T: ..>, it's not possible to set boundaries with where clause.

One particular usecase where it would be helpful is this one:

#[nutype(
    validate(predicate = |c| c.into_iter().next().is_some()),
)]
struct NonEmpty<C>(C)
where
    for<'a> &'a C: IntoIterator;

This would allow to define NonEmpty collection, regardless of what kind of collection it is.

See also https://github.com/greyblake/nutype/issues/130#issuecomment-2212415460

greyblake avatar Jul 07 '24 11:07 greyblake