enumflags2 icon indicating copy to clipboard operation
enumflags2 copied to clipboard

`impl From<N>` instead of `TryFrom<N>` where `N` matches `BitFlags<T, N>`

Open rockboynton opened this issue 1 year ago • 0 comments

For BitFlags<T, N> converting to N with bits() is infallible. Thus, it need not be a try_from() and instead just from() where the impl is just bits(). A user can't do this themselves because of the orphan rule unless they make a newtype.

i.e. when N == u8:

impl<T> From<BitFlags<T, u8>> for u8 {
    fn from(value: BitFlags<T, u8>) -> Self {
        value.bits()
    }
}

rockboynton avatar Mar 26 '24 23:03 rockboynton