@@ -694,26 +694,41 @@ not_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
694
694
///
695
695
/// # Examples
696
696
///
697
- /// A trivial implementation of `BitAnd`. When `Foo & Foo` happens, it ends up
698
- /// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!` .
697
+ /// In this example, the `BitAnd` trait is implemented for a `BooleanVector`
698
+ /// struct .
699
699
///
700
700
/// ```
701
701
/// use std::ops::BitAnd;
702
702
///
703
- /// struct Foo;
704
- ///
705
- /// impl BitAnd for Foo {
706
- /// type Output = Foo;
707
- ///
708
- /// fn bitand(self, _rhs: Foo) -> Foo {
709
- /// println!("Bitwise And-ing!");
710
- /// self
703
+ /// #[derive(Debug)]
704
+ /// struct BooleanVector {
705
+ /// value: Vec<bool>,
706
+ /// };
707
+ ///
708
+ /// impl BitAnd for BooleanVector {
709
+ /// type Output = Self;
710
+ ///
711
+ /// fn bitand(self, rhs: Self) -> Self {
712
+ /// BooleanVector {
713
+ /// value: self.value
714
+ /// .iter()
715
+ /// .zip(rhs.value.iter())
716
+ /// .map(|(x, y)| *x && *y)
717
+ /// .collect(),
718
+ /// }
711
719
/// }
712
720
/// }
713
721
///
714
- /// fn main() {
715
- /// Foo & Foo;
722
+ /// impl PartialEq for BooleanVector {
723
+ /// fn eq(&self, other: &Self) -> bool {
724
+ /// self.value == other.value
725
+ /// }
716
726
/// }
727
+ ///
728
+ /// let bv1 = BooleanVector { value: vec![true, true, false, false] };
729
+ /// let bv2 = BooleanVector { value: vec![true, false, true, false] };
730
+ /// let expected = BooleanVector { value: vec![true, false, false, false] };
731
+ /// assert_eq!(bv1 & bv2, expected);
717
732
/// ```
718
733
#[ lang = "bitand" ]
719
734
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments