Skip to content

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

Closed
@npmccallum

Description

@npmccallum
Contributor

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?

Activity

npmccallum

npmccallum commented on Sep 21, 2018

@npmccallum
ContributorAuthor

(The problem of how to handle usize on u32 given its variable size is a corner case...)

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Mar 23, 2019
jonas-schievink

jonas-schievink commented on Mar 23, 2019

@jonas-schievink
Contributor

Closing because of the issues encountered with the PR #54442. This can be prototyped in an external library (like cast), and might be addressed by rust-lang/rfcs#2484 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @npmccallum@jonas-schievink

      Issue actions

        Using BitAnd<T> for truncation on integer types? · Issue #54435 · rust-lang/rust