Skip to content

Commit

Permalink
Merge pull request #89 from wyhaya/impl_display
Browse files Browse the repository at this point in the history
Implement the Display trait for BitVec
  • Loading branch information
pczarn authored Jul 1, 2024
2 parents b00382f + d6928a2 commit 498dda6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ use alloc::vec::Vec;
use core::cell::RefCell;
use core::cmp;
use core::cmp::Ordering;
use core::fmt;
use core::fmt::{self, Write};
use core::hash;
use core::iter::repeat;
use core::iter::FromIterator;
Expand Down Expand Up @@ -1695,6 +1695,16 @@ impl<B: BitBlock> Ord for BitVec<B> {
}
}

impl<B: BitBlock> fmt::Display for BitVec<B> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.ensure_invariant();
for bit in self {
fmt.write_char(if bit { '1' } else { '0' })?;
}
Ok(())
}
}

impl<B: BitBlock> fmt::Debug for BitVec<B> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
self.ensure_invariant();
Expand Down

0 comments on commit 498dda6

Please sign in to comment.