Skip to content

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

@rockboynton

Description

@rockboynton

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()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions