greyblake / nutype

Rust newtype with guarantees πŸ‡ΊπŸ‡¦ πŸ¦€
MIT License
1.4k stars 23 forks source link

Respect `where` clause in generic newtypes #160

Open greyblake opened 3 months ago

greyblake commented 3 months ago

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