@@ -591,26 +591,41 @@ not_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
591
591
///
592
592
/// # Examples
593
593
///
594
- /// A trivial implementation of `BitAnd`. When `Foo & Foo` happens, it ends up
595
- /// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!` .
594
+ /// In this example, the `BitAnd` trait is implemented for a `BooleanVector`
595
+ /// struct .
596
596
///
597
597
/// ```
598
598
/// use std::ops::BitAnd;
599
599
///
600
- /// struct Foo;
601
- ///
602
- /// impl BitAnd for Foo {
603
- /// type Output = Foo;
604
- ///
605
- /// fn bitand(self, _rhs: Foo) -> Foo {
606
- /// println!("Bitwise And-ing!");
607
- /// self
600
+ /// #[derive(Debug)]
601
+ /// struct BooleanVector {
602
+ /// value: Vec<bool>,
603
+ /// };
604
+ ///
605
+ /// impl BitAnd for BooleanVector {
606
+ /// type Output = Self;
607
+ ///
608
+ /// fn bitand(self, rhs: Self) -> Self {
609
+ /// BooleanVector {
610
+ /// value: self.value
611
+ /// .iter()
612
+ /// .zip(rhs.value.iter())
613
+ /// .map(|(x, y)| *x && *y)
614
+ /// .collect(),
615
+ /// }
608
616
/// }
609
617
/// }
610
618
///
611
- /// fn main() {
612
- /// Foo & Foo;
619
+ /// impl PartialEq for BooleanVector {
620
+ /// fn eq(&self, other: &Self) -> bool {
621
+ /// self.value == other.value
622
+ /// }
613
623
/// }
624
+ ///
625
+ /// let bv1 = BooleanVector { value: vec![true, true, false, false] };
626
+ /// let bv2 = BooleanVector { value: vec![true, false, true, false] };
627
+ /// let expected = BooleanVector { value: vec![true, false, false, false] };
628
+ /// assert_eq!(bv1 & bv2, expected);
614
629
/// ```
615
630
#[ lang = "bitand" ]
616
631
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments