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 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<i8>
impl BitAnd for Saturating<i8>
type Output = Saturating<i8>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<i16>
impl BitAnd for Saturating<i16>
type Output = Saturating<i16>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<i32>
impl BitAnd for Saturating<i32>
type Output = Saturating<i32>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<i64>
impl BitAnd for Saturating<i64>
type Output = Saturating<i64>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<i128>
impl BitAnd for Saturating<i128>
type Output = Saturating<i128>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<isize>
impl BitAnd for Saturating<isize>
type Output = Saturating<isize>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<u8>
impl BitAnd for Saturating<u8>
type Output = Saturating<u8>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<u16>
impl BitAnd for Saturating<u16>
type Output = Saturating<u16>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<u32>
impl BitAnd for Saturating<u32>
type Output = Saturating<u32>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<u64>
impl BitAnd for Saturating<u64>
type Output = Saturating<u64>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd for Saturating<u128>
impl BitAnd for Saturating<u128>
type Output = Saturating<u128>
1.74.0 (const: unstable) ยท 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
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<i8>> for &Saturating<i8>
impl BitAnd<&Saturating<i8>> for &Saturating<i8>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<i8>> for Saturating<i8>
impl BitAnd<&Saturating<i8>> for Saturating<i8>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<i16>> for &Saturating<i16>
impl BitAnd<&Saturating<i16>> for &Saturating<i16>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<i16>> for Saturating<i16>
impl BitAnd<&Saturating<i16>> for Saturating<i16>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<i32>> for &Saturating<i32>
impl BitAnd<&Saturating<i32>> for &Saturating<i32>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<i32>> for Saturating<i32>
impl BitAnd<&Saturating<i32>> for Saturating<i32>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<i64>> for &Saturating<i64>
impl BitAnd<&Saturating<i64>> for &Saturating<i64>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<i64>> for Saturating<i64>
impl BitAnd<&Saturating<i64>> for Saturating<i64>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<i128>> for &Saturating<i128>
impl BitAnd<&Saturating<i128>> for &Saturating<i128>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<i128>> for Saturating<i128>
impl BitAnd<&Saturating<i128>> for Saturating<i128>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<isize>> for &Saturating<isize>
impl BitAnd<&Saturating<isize>> for &Saturating<isize>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<isize>> for Saturating<isize>
impl BitAnd<&Saturating<isize>> for Saturating<isize>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<u8>> for &Saturating<u8>
impl BitAnd<&Saturating<u8>> for &Saturating<u8>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<u8>> for Saturating<u8>
impl BitAnd<&Saturating<u8>> for Saturating<u8>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<u16>> for &Saturating<u16>
impl BitAnd<&Saturating<u16>> for &Saturating<u16>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<u16>> for Saturating<u16>
impl BitAnd<&Saturating<u16>> for Saturating<u16>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<u32>> for &Saturating<u32>
impl BitAnd<&Saturating<u32>> for &Saturating<u32>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<u32>> for Saturating<u32>
impl BitAnd<&Saturating<u32>> for Saturating<u32>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<u64>> for &Saturating<u64>
impl BitAnd<&Saturating<u64>> for &Saturating<u64>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<u64>> for Saturating<u64>
impl BitAnd<&Saturating<u64>> for Saturating<u64>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<u128>> for &Saturating<u128>
impl BitAnd<&Saturating<u128>> for &Saturating<u128>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<u128>> for Saturating<u128>
impl BitAnd<&Saturating<u128>> for Saturating<u128>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<usize>> for &Saturating<usize>
impl BitAnd<&Saturating<usize>> for &Saturating<usize>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<&Saturating<usize>> for Saturating<usize>
impl BitAnd<&Saturating<usize>> for Saturating<usize>
ยงimpl BitAnd<(SimpleUriName, Language)> for ArchiveUri
Adds a document [SimpleUriName] to an [ArchiveUri] to create a [DocumentUri].
impl BitAnd<(SimpleUriName, Language)> for ArchiveUri
Adds a document [SimpleUriName] to an [ArchiveUri] to create a [DocumentUri].
ยงExamples
let archive = ArchiveUri::from_str("http://example.com?a=archive").unwrap();
let name = SimpleUriName::from_str("math").unwrap();
let document_uri = archive & (name,Language::English);
assert_eq!(document_uri.to_string(), "http://example.com?a=archive&d=math&l=en");ยงimpl BitAnd<(SimpleUriName, Language)> for PathUri
Adds a document [SimpleUriName] to a [PathUri] to create a [DocumentUri].
impl BitAnd<(SimpleUriName, Language)> for PathUri
Adds a document [SimpleUriName] to a [PathUri] to create a [DocumentUri].
ยงExamples
let path_uri = PathUri::from_str("http://example.com?a=archive&p=folder").unwrap();
let name = SimpleUriName::from_str("document").unwrap();
let document_uri = path_uri & (name,Language::German);
assert_eq!(document_uri.to_string(), "http://example.com?a=archive&p=folder&d=document&l=de");1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<i8>> for &Saturating<i8>
impl BitAnd<Saturating<i8>> for &Saturating<i8>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<i16>> for &Saturating<i16>
impl BitAnd<Saturating<i16>> for &Saturating<i16>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<i32>> for &Saturating<i32>
impl BitAnd<Saturating<i32>> for &Saturating<i32>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<i64>> for &Saturating<i64>
impl BitAnd<Saturating<i64>> for &Saturating<i64>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<i128>> for &Saturating<i128>
impl BitAnd<Saturating<i128>> for &Saturating<i128>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<isize>> for &Saturating<isize>
impl BitAnd<Saturating<isize>> for &Saturating<isize>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<u8>> for &Saturating<u8>
impl BitAnd<Saturating<u8>> for &Saturating<u8>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<u16>> for &Saturating<u16>
impl BitAnd<Saturating<u16>> for &Saturating<u16>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<u32>> for &Saturating<u32>
impl BitAnd<Saturating<u32>> for &Saturating<u32>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<u64>> for &Saturating<u64>
impl BitAnd<Saturating<u64>> for &Saturating<u64>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<u128>> for &Saturating<u128>
impl BitAnd<Saturating<u128>> for &Saturating<u128>
1.74.0 (const: unstable) ยท Sourceยงimpl BitAnd<Saturating<usize>> for &Saturating<usize>
impl BitAnd<Saturating<usize>> for &Saturating<usize>
ยงimpl BitAnd<ArchiveId> for BaseUri
Combines a [BaseUri] with an [ArchiveId] to create an [ArchiveUri].
impl BitAnd<ArchiveId> for BaseUri
Combines a [BaseUri] with an [ArchiveId] to create an [ArchiveUri].
ยงExamples
let base = BaseUri::from_str("http://example.com").unwrap();
let archive_id = ArchiveId::from_str("my/archive").unwrap();
let archive_uri = base & archive_id;
assert_eq!(archive_uri.to_string(), "http://example.com?a=my/archive");ยงimpl BitAnd<UriName> for DocumentUri
Adds an element name [UriName] to a [DocumentUri] to create a [DocumentElementUri].
impl BitAnd<UriName> for DocumentUri
Adds an element name [UriName] to a [DocumentUri] to create a [DocumentElementUri].
ยงExamples
let document_uri = DocumentUri::from_str("http://example.com?a=archive&p=folder&d=foo&l=fr").unwrap();
let name = UriName::from_str("bar").unwrap();
let element_uri = document_uri & name;
assert_eq!(element_uri.to_string(), "http://example.com?a=archive&p=folder&d=foo&l=fr&e=bar");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.