Closed
Description
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 commentedon Sep 21, 2018
(The problem of how to handle
usize
on u32 given its variable size is a corner case...)jonas-schievink commentedon Mar 23, 2019
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.