Skip to content

Arrays should impl the bitwise operations #2773

Open
@canndrew

Description

@canndrew

I have a couple [u8; 8]s that I'd like to xor with each other. Unfortunately this doesn't work:

let x = [0u8; 8];
let y = [1u8; 8];
let z = x ^ y;

I think it should, since this has pretty clear semantics. More generally I think it would make sense to have an impl:

impl<const N: usize, A, B> BitXor<[B; N]> for [A; N]
where
    A: BitXor<B>,
{
    type Output = [<A as BitXor<B>>::Output; N];

    fn bitxor(self, rhs: [B; N]) -> Self::Output {
        ...
    }
}

And similar for BitAnd and BitOr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-arithmeticArithmetic related proposals & ideasA-arrayArray related proposals & ideasA-operatorOperators related proposals.T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions