Skip to content

Commit

Permalink
Merge pull request #55 from contain-rs/display-debug
Browse files Browse the repository at this point in the history
Implement Display and fix Debug
  • Loading branch information
pczarn authored Dec 1, 2024
2 parents bac79d3 + c85d5c8 commit ded2cb6
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,14 @@ impl<B: BitBlock> BitSet<B> {
}

impl<B: BitBlock> fmt::Debug for BitSet<B> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("BitSet")
.field("bit_vec", &self.bit_vec)
.finish()
}
}

impl<B: BitBlock> fmt::Display for BitSet<B> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_set().entries(self).finish()
}
Expand Down Expand Up @@ -1144,13 +1152,27 @@ mod tests {
use std::{format, vec};

#[test]
fn test_bit_set_show() {
fn test_bit_set_display() {
let mut s = BitSet::new();
s.insert(1);
s.insert(10);
s.insert(50);
s.insert(2);
assert_eq!("{1, 2, 10, 50}", format!("{}", s));
}

#[test]
fn test_bit_set_debug() {
let mut s = BitSet::new();
s.insert(1);
s.insert(10);
s.insert(50);
s.insert(2);
assert_eq!("{1, 2, 10, 50}", format!("{:?}", s));
let expected = "BitSet { bit_vec: BitVec { storage: \
\"01100000001000000000000000000000 \
0000000000000000001\", nbits: 51 } }";
let actual = format!("{:?}", s);
assert_eq!(expected, actual);
}

#[test]
Expand Down

0 comments on commit ded2cb6

Please sign in to comment.