derive_more
derive_more copied to clipboard
A derived trait providing access to the inner type of a newtype
trafficstars
While derived From and AsRef already remove some boilerplate when defining newtypes, it would be convenient to have a more specialized "newtype" trait that would give access to the inner type. That is, derive_more would define
trait Newtype {
type Inner;
}
And writing
#[derive(Newtype)]
struct Outer(SomeType);
would produce
impl Newtype for Outer {
type Inner = SomeType;
}
The associated Inner may be bounded:
trait Newtype: Sized {
type Inner: Into<Self>;
}
In which case #[derive(Newtype)] would also derive From.
Does that sound like something you'd want to add to the crate? I can make a PR.