pub trait BitAnd<Rhs = Self> {
type Output;
// Required method
fn bitand(self, rhs: Rhs) -> Self::Output;
}
Expand description
The bitwise AND operator &
.
Note that Rhs
is Self
by default, but this is not mandatory.
ยงExamples
An implementation of BitAnd
for a wrapper around bool
.
use std::ops::BitAnd;
#[derive(Debug, PartialEq)]
struct Scalar(bool);
impl BitAnd for Scalar {
type Output = Self;
// rhs is the "right-hand side" of the expression `a & b`
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0 & rhs.0)
}
}
assert_eq!(Scalar(true) & Scalar(true), Scalar(true));
assert_eq!(Scalar(true) & Scalar(false), Scalar(false));
assert_eq!(Scalar(false) & Scalar(true), Scalar(false));
assert_eq!(Scalar(false) & Scalar(false), Scalar(false));
An implementation of BitAnd
for a wrapper around Vec<bool>
.
use std::ops::BitAnd;
#[derive(Debug, PartialEq)]
struct BooleanVector(Vec<bool>);
impl BitAnd for BooleanVector {
type Output = Self;
fn bitand(self, Self(rhs): Self) -> Self::Output {
let Self(lhs) = self;
assert_eq!(lhs.len(), rhs.len());
Self(
lhs.iter()
.zip(rhs.iter())
.map(|(x, y)| *x & *y)
.collect()
)
}
}
let bv1 = BooleanVector(vec![true, true, false, false]);
let bv2 = BooleanVector(vec![true, false, true, false]);
let expected = BooleanVector(vec![true, false, false, false]);
assert_eq!(bv1 & bv2, expected);
Required Associated Typesยง
Required Methodsยง
Implementorsยง
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<i8>
impl BitAnd for Saturating<i8>
type Output = Saturating<i8>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<i16>
impl BitAnd for Saturating<i16>
type Output = Saturating<i16>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<i32>
impl BitAnd for Saturating<i32>
type Output = Saturating<i32>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<i64>
impl BitAnd for Saturating<i64>
type Output = Saturating<i64>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<i128>
impl BitAnd for Saturating<i128>
type Output = Saturating<i128>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<isize>
impl BitAnd for Saturating<isize>
type Output = Saturating<isize>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<u8>
impl BitAnd for Saturating<u8>
type Output = Saturating<u8>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<u16>
impl BitAnd for Saturating<u16>
type Output = Saturating<u16>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<u32>
impl BitAnd for Saturating<u32>
type Output = Saturating<u32>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<u64>
impl BitAnd for Saturating<u64>
type Output = Saturating<u64>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<u128>
impl BitAnd for Saturating<u128>
type Output = Saturating<u128>
1.74.0 ยท Sourceยงimpl BitAnd for Saturating<usize>
impl BitAnd for Saturating<usize>
type Output = Saturating<usize>
Sourceยงimpl BitAnd for AttrCheckFlags
impl BitAnd for AttrCheckFlags
type Output = AttrCheckFlags
Sourceยงimpl BitAnd for CredentialType
impl BitAnd for CredentialType
type Output = CredentialType
Sourceยงimpl BitAnd for DiffStatsFormat
impl BitAnd for DiffStatsFormat
type Output = DiffStatsFormat
Sourceยงimpl BitAnd for IndexAddOption
impl BitAnd for IndexAddOption
type Output = IndexAddOption
Sourceยงimpl BitAnd for IndexEntryExtendedFlag
impl BitAnd for IndexEntryExtendedFlag
Sourceยงimpl BitAnd for IndexEntryFlag
impl BitAnd for IndexEntryFlag
type Output = IndexEntryFlag
Sourceยงimpl BitAnd for MergeAnalysis
impl BitAnd for MergeAnalysis
type Output = MergeAnalysis
Sourceยงimpl BitAnd for MergePreference
impl BitAnd for MergePreference
type Output = MergePreference
Sourceยงimpl BitAnd for OdbLookupFlags
impl BitAnd for OdbLookupFlags
type Output = OdbLookupFlags
Sourceยงimpl BitAnd for PathspecFlags
impl BitAnd for PathspecFlags
type Output = PathspecFlags
Sourceยงimpl BitAnd for ReferenceFormat
impl BitAnd for ReferenceFormat
type Output = ReferenceFormat
Sourceยงimpl BitAnd for RemoteUpdateFlags
impl BitAnd for RemoteUpdateFlags
type Output = RemoteUpdateFlags
Sourceยงimpl BitAnd for RepositoryInitMode
impl BitAnd for RepositoryInitMode
type Output = RepositoryInitMode
Sourceยงimpl BitAnd for RepositoryOpenFlags
impl BitAnd for RepositoryOpenFlags
Sourceยงimpl BitAnd for RevparseMode
impl BitAnd for RevparseMode
type Output = RevparseMode
Sourceยงimpl BitAnd for StashApplyFlags
impl BitAnd for StashApplyFlags
type Output = StashApplyFlags
Sourceยงimpl BitAnd for StashFlags
impl BitAnd for StashFlags
type Output = StashFlags
Sourceยงimpl BitAnd for SubmoduleStatus
impl BitAnd for SubmoduleStatus
type Output = SubmoduleStatus
Sourceยงimpl BitAnd for CipherCtxFlags
impl BitAnd for CipherCtxFlags
type Output = CipherCtxFlags
Sourceยงimpl BitAnd for CMSOptions
impl BitAnd for CMSOptions
type Output = CMSOptions
Sourceยงimpl BitAnd for Pkcs7Flags
impl BitAnd for Pkcs7Flags
type Output = Pkcs7Flags
Sourceยงimpl BitAnd for ExtensionContext
impl BitAnd for ExtensionContext
type Output = ExtensionContext
Sourceยงimpl BitAnd for ShutdownState
impl BitAnd for ShutdownState
type Output = ShutdownState
Sourceยงimpl BitAnd for SslOptions
impl BitAnd for SslOptions
type Output = SslOptions
Sourceยงimpl BitAnd for SslSessionCacheMode
impl BitAnd for SslSessionCacheMode
Sourceยงimpl BitAnd for SslVerifyMode
impl BitAnd for SslVerifyMode
type Output = SslVerifyMode
Sourceยงimpl BitAnd for X509CheckFlags
impl BitAnd for X509CheckFlags
type Output = X509CheckFlags
Sourceยงimpl BitAnd for X509VerifyFlags
impl BitAnd for X509VerifyFlags
type Output = X509VerifyFlags
Sourceยงimpl BitAnd<&str> for NarrativeURI
impl BitAnd<&str> for NarrativeURI
Sourceยงimpl BitAnd<&str> for ArchiveURI
impl BitAnd<&str> for ArchiveURI
Sourceยงimpl BitAnd<&str> for DocumentURI
impl BitAnd<&str> for DocumentURI
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<i8>> for &Saturating<i8>
impl BitAnd<&Saturating<i8>> for &Saturating<i8>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<i8>> for Saturating<i8>
impl BitAnd<&Saturating<i8>> for Saturating<i8>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<i16>> for &Saturating<i16>
impl BitAnd<&Saturating<i16>> for &Saturating<i16>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<i16>> for Saturating<i16>
impl BitAnd<&Saturating<i16>> for Saturating<i16>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<i32>> for &Saturating<i32>
impl BitAnd<&Saturating<i32>> for &Saturating<i32>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<i32>> for Saturating<i32>
impl BitAnd<&Saturating<i32>> for Saturating<i32>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<i64>> for &Saturating<i64>
impl BitAnd<&Saturating<i64>> for &Saturating<i64>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<i64>> for Saturating<i64>
impl BitAnd<&Saturating<i64>> for Saturating<i64>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<i128>> for &Saturating<i128>
impl BitAnd<&Saturating<i128>> for &Saturating<i128>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<i128>> for Saturating<i128>
impl BitAnd<&Saturating<i128>> for Saturating<i128>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<isize>> for &Saturating<isize>
impl BitAnd<&Saturating<isize>> for &Saturating<isize>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<isize>> for Saturating<isize>
impl BitAnd<&Saturating<isize>> for Saturating<isize>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<u8>> for &Saturating<u8>
impl BitAnd<&Saturating<u8>> for &Saturating<u8>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<u8>> for Saturating<u8>
impl BitAnd<&Saturating<u8>> for Saturating<u8>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<u16>> for &Saturating<u16>
impl BitAnd<&Saturating<u16>> for &Saturating<u16>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<u16>> for Saturating<u16>
impl BitAnd<&Saturating<u16>> for Saturating<u16>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<u32>> for &Saturating<u32>
impl BitAnd<&Saturating<u32>> for &Saturating<u32>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<u32>> for Saturating<u32>
impl BitAnd<&Saturating<u32>> for Saturating<u32>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<u64>> for &Saturating<u64>
impl BitAnd<&Saturating<u64>> for &Saturating<u64>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<u64>> for Saturating<u64>
impl BitAnd<&Saturating<u64>> for Saturating<u64>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<u128>> for &Saturating<u128>
impl BitAnd<&Saturating<u128>> for &Saturating<u128>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<u128>> for Saturating<u128>
impl BitAnd<&Saturating<u128>> for Saturating<u128>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<usize>> for &Saturating<usize>
impl BitAnd<&Saturating<usize>> for &Saturating<usize>
1.74.0 ยท Sourceยงimpl BitAnd<&Saturating<usize>> for Saturating<usize>
impl BitAnd<&Saturating<usize>> for Saturating<usize>
Sourceยงimpl BitAnd<(Name, Language)> for ArchiveURI
impl BitAnd<(Name, Language)> for ArchiveURI
type Output = DocumentURI
Sourceยงimpl BitAnd<Name> for NarrativeURI
impl BitAnd<Name> for NarrativeURI
type Output = DocumentElementURI
Sourceยงimpl BitAnd<Name> for ArchiveURI
impl BitAnd<Name> for ArchiveURI
type Output = DocumentURI
Sourceยงimpl BitAnd<Name> for DocumentURI
impl BitAnd<Name> for DocumentURI
type Output = DocumentElementURI
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<i8>> for &'a Saturating<i8>
impl<'a> BitAnd<Saturating<i8>> for &'a Saturating<i8>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<i16>> for &'a Saturating<i16>
impl<'a> BitAnd<Saturating<i16>> for &'a Saturating<i16>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<i32>> for &'a Saturating<i32>
impl<'a> BitAnd<Saturating<i32>> for &'a Saturating<i32>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<i64>> for &'a Saturating<i64>
impl<'a> BitAnd<Saturating<i64>> for &'a Saturating<i64>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<i128>> for &'a Saturating<i128>
impl<'a> BitAnd<Saturating<i128>> for &'a Saturating<i128>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<isize>> for &'a Saturating<isize>
impl<'a> BitAnd<Saturating<isize>> for &'a Saturating<isize>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<u8>> for &'a Saturating<u8>
impl<'a> BitAnd<Saturating<u8>> for &'a Saturating<u8>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<u16>> for &'a Saturating<u16>
impl<'a> BitAnd<Saturating<u16>> for &'a Saturating<u16>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<u32>> for &'a Saturating<u32>
impl<'a> BitAnd<Saturating<u32>> for &'a Saturating<u32>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<u64>> for &'a Saturating<u64>
impl<'a> BitAnd<Saturating<u64>> for &'a Saturating<u64>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<u128>> for &'a Saturating<u128>
impl<'a> BitAnd<Saturating<u128>> for &'a Saturating<u128>
1.74.0 ยท Sourceยงimpl<'a> BitAnd<Saturating<usize>> for &'a Saturating<usize>
impl<'a> BitAnd<Saturating<usize>> for &'a Saturating<usize>
Sourceยงimpl<Ul, Bl, Ur> BitAnd<Ur> for UInt<Ul, Bl>where
Ul: Unsigned,
Bl: Bit,
Ur: Unsigned,
UInt<Ul, Bl>: PrivateAnd<Ur>,
<UInt<Ul, Bl> as PrivateAnd<Ur>>::Output: Trim,
Anding unsigned integers.
We use our PrivateAnd
operator and then Trim
the output.
impl<Ul, Bl, Ur> BitAnd<Ur> for UInt<Ul, Bl>where
Ul: Unsigned,
Bl: Bit,
Ur: Unsigned,
UInt<Ul, Bl>: PrivateAnd<Ur>,
<UInt<Ul, Bl> as PrivateAnd<Ur>>::Output: Trim,
Anding unsigned integers.
We use our PrivateAnd
operator and then Trim
the output.