Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
npmccallum opened this issue Sep 21, 2018 · 2 comments
Closed

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

npmccallum opened this issue Sep 21, 2018 · 2 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@npmccallum
Copy link
Contributor

npmccallum commented Sep 21, 2018

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?

@npmccallum
Copy link
Contributor Author

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

@jonas-schievink jonas-schievink added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 23, 2019
@jonas-schievink
Copy link
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
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants