Skip to content

Using BitAnd<T> for truncation on integer types? #54435

Closed
@npmccallum

Description

@npmccallum

Would rust be willing to take a pull request that implements BitAnd on integer types for all smaller versions of the int?

For example:

impl BitAnd<u64> for u128 { type Output = u64 }
impl BitAnd<u32> for u128 { type Output = u32 }
impl BitAnd<u16> for u128 { type Output = u16 }
impl BitAnd<u8> for u128 { type Output = u8 }

impl BitAnd<u32> for u64 { type Output = u32 }
impl BitAnd<u16> for u64 { type Output = u16 }
impl BitAnd<u8> for u64 { type Output = u8 }

impl BitAnd<u16> for u32 { type Output = u16 }
impl BitAnd<u8> for u32 { type Output = u8 }

impl BitAnd<u8> for u16 { type Output = u8 }

This would enable effortless, correct and infallible truncation in generic contexts. Is this problem sophisticated enough to warrant an RFC?

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions