num-derive
num-derive copied to clipboard
Implement derives for generic wrapper types
fixes #19
Rebased
Just missed a couple spots.
oops, resolved and grepped to see if there are any others (there weren't).
Oh. I just realized that
#[derive(
Debug,
Clone,
Copy,
PartialEq,
PartialOrd,
ToPrimitive,
FromPrimitive,
NumOps,
NumCast,
One,
Zero,
Num,
)]
struct MyThing<T>(Wrapping<T>);
does not work, because there's no T: Num
bound on the Num
impl, causing rustc to fail to infer that Wrapping<T>: Num
holds. If we add T: Num
bounds, that makes struct MyThing<T, U>(SomeTypeImplingNumEvenIfTDoesNot<T>);
not work anymore.
because there's no
T: Num
bound on theNum
impl, causing rustc to fail to infer thatWrapping<T>: Num
holds. If we addT: Num
bounds, that makesstruct MyThing<T, U>(SomeTypeImplingNumEvenIfTDoesNot<T>);
not work anymore.
Hmm, now it seems like we're in that gray area of https://github.com/rust-lang/rust/issues/26925, where it's not really obvious whether you should want bounds on the generic parameters or on the structural types. By adding #inner_ty: Trait
, we're leaking that private type in a way that may not be desirable. I think we should probably only constrain the generic parameters, as the compiler does.
So far we've avoided this question because the newtype derivations are unconditional.