New:Socket for Asana Is Now Available.Learn more
Get Started

bitvec

Package Overview
Dependencies
Maintainers
0
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitvec - cargo Package Compare versions

Package version was removed
This package version has been unpublished, mostly likely due to security reasons
Comparing version
0.3.0
to
0.4.0
+1
-1
Cargo.toml

@@ -15,3 +15,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO

name = "bitvec"
version = "0.3.0"
version = "0.4.0"
authors = ["myrrlyn <myrrlyn@outlook.com>"]

@@ -18,0 +18,0 @@ description = "A crate for manipulating memory, bit by bit"

@@ -5,2 +5,49 @@ # Changelog

## 0.4.0
### Added
`BitSlice::for_each` provides mutable iteration over a slice. It yields each
successive `(index: usize, bit: bool)` pair to a closure, and stores the return
value of that closure at the yielded index.
`BitVec` now implements `Eq` and `Ord` against other `BitVec`s. It is impossible
at this time to make `BitVec` generic over anything that is `Borrow<BitSlice>`,
which would allow comparisons over different ownership types. The declaration
```rust
impl<A, B, C, D, E> PartialEq<C> for BitVec<A, B>
where A: Endian,
B: Bits,
C: Borrow<BitSlice<D, E>>,
D: Endian,
E: Bits,
{
fn eq(&self, rhs: E) { ... }
}
```
is impossible to write, so `BitVec == BitSlice` will be rejected.
As with many other traits on `BitVec`, the implementations are just a thin
wrapper over the corresponding `BitSlice` implementations.
### Changed
Refine the API documentation. Rust guidelines recommend imperative rather than
descriptive summaries for function documentation, which largely meant stripping
the trailing -s from the first verb in each function document.
I also moved the example code from the trait-level documentation to the
function-level documentation, so that it would show up an `type::func` in the
`rustdoc` output rather than just `type`. This makes it much clearer what is
being tested.
### Removed
`BitVec` methods `iter` and `raw_len` moved to `BitSlice` in `0.3.0` but were
not removed in that release.
The remaining debugging `eprintln!` calls have been stripped.
## 0.3.0

@@ -7,0 +54,0 @@

@@ -41,3 +41,3 @@ # `BitVec` – Managing memory bit by bit

[dependencies]
bitvec = "0.1"
bitvec = "0.4"
```

@@ -44,0 +44,0 @@

@@ -141,3 +141,2 @@ /*! Endianness Markers

let pos = (far & (T::MASK as isize)) as u8;
eprintln!("{}, {}", elements, Self::curr::<T>(pos));
(elements, Self::curr::<T>(pos))

@@ -148,4 +147,2 @@ },

(far, _) => {
eprintln!("DID NOT BREACH");
eprintln!("{}, {}", far, Self::curr::<T>(far as u8));
(0, Self::curr::<T>(far as u8))

@@ -152,0 +149,0 @@ },

+287
-206

@@ -50,5 +50,5 @@ /*! `BitSlice` Wide Reference

Ord,
Ordering,
PartialEq,
PartialOrd,
Ordering,
};

@@ -245,3 +245,3 @@ use std::convert::{

/// Provides read-only iteration across the collection.
/// Provide read-only iteration across the collection.
///

@@ -255,3 +255,34 @@ /// The iterator returned from this method implements `ExactSizeIterator`

/// Retrieves a read pointer to the start of the data slice.
/// Provide mutable traversal of the collection.
///
/// It is impossible to implement `IndexMut` on `BitSlice` because bits do
/// not have addresses, so there can be no `&mut u1`. This method allows the
/// client to receive an enumerated bit, and provide a new bit to set at
/// each index.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![1; 8];
/// let bref: &mut BitSlice = &mut bv;
/// bref.for_each(|idx, bit| {
/// if idx % 2 == 0 {
/// !bit
/// }
/// else {
/// bit
/// }
/// });
/// assert_eq!(&[0b01010101], bref.as_ref());
/// ```
pub fn for_each<'a, F>(&'a mut self, op: F)
where F: Fn(usize, bool) -> bool {
for idx in 0 .. self.len() {
let tmp = self.get(idx);
self.set(idx, op(idx, tmp));
}
}
/// Retrieve a read pointer to the start of the data slice.
pub(crate) fn as_ptr(&self) -> *const T {

@@ -261,3 +292,3 @@ self.inner.as_ptr()

/// Retrieves a write pointer to the start of the data slice.
/// Retrieve a write pointer to the start of the data slice.
pub(crate) fn as_mut_ptr(&mut self) -> *mut T {

@@ -267,3 +298,3 @@ self.inner.as_mut_ptr()

/// Computes the actual length of the data slice, including the partial tail
/// Compute the actual length of the data slice, including the partial tail
/// if any.

@@ -284,3 +315,3 @@ ///

/// Prints a type header into the Formatter.
/// Print a type header into the Formatter.
pub(crate) fn fmt_header(&self, fmt: &mut Formatter) -> fmt::Result {

@@ -290,3 +321,3 @@ write!(fmt, "BitSlice<{}, {}>", E::TY, T::TY)

/// Formats the contents data slice.
/// Format the contents data slice.
///

@@ -321,3 +352,3 @@ /// The debug flag indicates whether to indent each line (`Debug` does,

/// Formats a whole storage element of the data slice.
/// Format a whole storage element of the data slice.
pub(crate) fn fmt_element(fmt: &mut Formatter, elt: &T) -> fmt::Result {

@@ -327,3 +358,3 @@ Self::fmt_bits(fmt, elt, T::WIDTH)

/// Formats a partial element of the data slice.
/// Format a partial element of the data slice.
pub(crate) fn fmt_bits(fmt: &mut Formatter, elt: &T, bits: u8) -> fmt::Result {

@@ -340,18 +371,18 @@ use std::fmt::Write;

/// Gives write access to all elements in the underlying storage, including the
/// Give write access to all elements in the underlying storage, including the
/// partially-filled tail element (if present).
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bytes: &mut [u8] = &mut [5, 10, 15, 20, 25];
/// let bits: &mut BitSlice = bytes.into();
/// for elt in bits.as_mut() {
/// *elt += 2;
/// }
/// assert_eq!(&[7, 12, 17, 22, 27], bits.as_ref());
/// ```
impl<E, T> AsMut<[T]> for BitSlice<E, T>
where E: Endian, T: Bits {
/// Access the underlying store.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv: BitVec = bitvec![0, 0, 0, 0, 0, 0, 0, 0, 1];
/// for elt in bv.as_mut() {
/// *elt += 2;
/// }
/// assert_eq!(&[2, 0b1000_0010], bv.as_ref());
/// ```
fn as_mut(&mut self) -> &mut [T] {

@@ -363,15 +394,16 @@ let (ptr, len): (*mut T, usize) = (self.as_mut_ptr(), self.raw_len());

/// Gives read access to all elements in the underlying storage, including the
/// Give read access to all elements in the underlying storage, including the
/// partially-filled tail element (if present).
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bytes: &[u8] = &[5, 10, 15, 20, 25];
/// let bits: &BitSlice = bytes.into();
/// assert_eq!(&[5, 10, 15, 20, 25], bits.as_ref());
/// ```
impl<E, T> AsRef<[T]> for BitSlice<E, T>
where E: Endian, T: Bits {
/// Access the underlying store.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![0, 0, 0, 0, 0, 0, 0, 0, 1];
/// let bref: &BitSlice = &bv;
/// assert_eq!(&[0, 0b1000_0000], bref.as_ref());
/// ```
fn as_ref(&self) -> &[T] {

@@ -386,14 +418,15 @@ let (ptr, len): (*const T, usize) = (self.as_ptr(), self.raw_len());

/// extended with zero, clearing all remaining bits in `self`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs: &mut BitSlice = &mut bitvec![0, 1, 0, 1, 0, 1];
/// let rhs = bitvec![0, 0, 1, 1];
/// *lhs &= rhs;
/// assert_eq!("000100", &format!("{}", lhs));
/// ```
impl<E, T, I> BitAndAssign<I> for BitSlice<E, T>
where E: Endian, T: Bits, I: IntoIterator<Item=bool> {
/// AND a bitstream inta a slice.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs: &mut BitSlice = &mut bitvec![0, 1, 0, 1, 0, 1];
/// let rhs = bitvec![0, 0, 1, 1];
/// *lhs &= rhs;
/// assert_eq!("000100", &format!("{}", lhs));
/// ```
fn bitand_assign(&mut self, rhs: I) {

@@ -411,14 +444,15 @@ use std::iter::repeat;

/// extended with zero, leaving all remaining bits in `self` as they were.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs: &mut BitSlice = &mut bitvec![0, 1, 0, 1, 0, 1];
/// let rhs = bitvec![0, 0, 1, 1];
/// *lhs |= rhs;
/// assert_eq!("011101", &format!("{}", lhs));
/// ```
impl<E, T, I> BitOrAssign<I> for BitSlice<E, T>
where E: Endian, T: Bits, I: IntoIterator<Item=bool> {
/// OR a bitstream into a slice.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs: &mut BitSlice = &mut bitvec![0, 1, 0, 1, 0, 1];
/// let rhs = bitvec![0, 0, 1, 1];
/// *lhs |= rhs;
/// assert_eq!("011101", &format!("{}", lhs));
/// ```
fn bitor_assign(&mut self, rhs: I) {

@@ -432,17 +466,18 @@ for (idx, other) in (0 .. self.len()).zip(rhs.into_iter()) {

/// Performs the Boolean XOR operation against another bitstream and writes the
/// Perform the Boolean XOR operation against another bitstream and writes the
/// result into `self`. If the other bitstream ends before `self` does, it is
/// extended with zero, leaving all remaining bits in `self` as they were.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs: &mut BitSlice = &mut bitvec![0, 1, 0, 1, 0, 1];
/// let rhs = bitvec![0, 0, 1, 1];
/// *lhs ^= rhs;
/// assert_eq!("011001", &format!("{}", lhs));
/// ```
impl<E, T, I> BitXorAssign<I> for BitSlice<E, T>
where E: Endian, T: Bits, I: IntoIterator<Item=bool> {
/// XOR a bitstream into a slice.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs: &mut BitSlice = &mut bitvec![0, 1, 0, 1, 0, 1];
/// let rhs = bitvec![0, 0, 1, 1];
/// *lhs ^= rhs;
/// assert_eq!("011001", &format!("{}", lhs));
/// ```
fn bitxor_assign(&mut self, rhs: I) {

@@ -457,3 +492,3 @@ use std::iter::repeat;

/// Prints the `BitSlice` for debugging.
/// Print the `BitSlice` for debugging.
///

@@ -468,16 +503,20 @@ /// The output is of the form `BitSlice<E, T> [ELT, *]` where `<E, T>` is the

/// than having all elements on the same line.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bits: &BitSlice<LittleEndian, u16> = &bitvec![
/// LittleEndian, u16;
/// 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1,
/// 0, 1
/// ];
/// assert_eq!("BitSlice<LittleEndian, u16> [0101000011110101, 01]", &format!("{:?}", bits));
/// ```
impl<E, T> Debug for BitSlice<E, T>
where E: Endian, T: Bits {
/// Render the `BitSlice` type header and contents for debug.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bits: &BitSlice<LittleEndian, u16> = &bitvec![
/// LittleEndian, u16;
/// 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1,
/// 0, 1
/// ];
/// assert_eq!(
/// "BitSlice<LittleEndian, u16> [0101000011110101, 01]",
/// &format!("{:?}", bits)
/// );
/// ```
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {

@@ -504,12 +543,13 @@ let alt = fmt.alternate();

/// raw elements and print that slice instead.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bits: &BitSlice = &bitvec![0, 1, 0, 0, 1, 0, 1, 1, 0, 1];
/// assert_eq!("01001011 01", &format!("{}", bits));
/// ```
impl<E, T> Display for BitSlice<E, T>
where E: Endian, T: Bits {
/// Renders the `BitSlice` contents for display.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bits: &BitSlice = &bitvec![0, 1, 0, 0, 1, 0, 1, 1, 0, 1];
/// assert_eq!("01001011 01", &format!("{}", bits));
/// ```
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {

@@ -520,22 +560,24 @@ self.fmt_body(fmt, false)

/// Builds a `BitSlice` from a slice of elements. The resulting `BitSlice` will
/// Build a `BitSlice` from a slice of elements. The resulting `BitSlice` will
/// always completely fill the original slice, and will not have a partial tail.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src = vec![1u8, 2, 3];
/// let borrow: &[u8] = &src;
/// let bits: &BitSlice = borrow.into();
/// assert_eq!(bits.len(), 24);
/// assert_eq!(bits.elts(), 3);
/// assert_eq!(bits.bits(), 0);
/// assert!(bits.get(7)); // src[0] == 0b0000_0001
/// assert!(bits.get(14)); // src[1] == 0b0000_0010
/// assert!(bits.get(22)); // src[2] == 0b0000_0011
/// assert!(bits.get(23));
/// ```
impl<'a, E, T> From<&'a [T]> for &'a BitSlice<E, T>
where E: Endian, T: 'a + Bits {
/// Wrap an `&[T: Bits]` in an `&BitSlice<E: Endian, T>`. The endianness
/// must be specified by the call site. The element type cannot be changed.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src = vec![1u8, 2, 3];
/// let borrow: &[u8] = &src;
/// let bits: &BitSlice<BigEndian, _> = borrow.into();
/// assert_eq!(bits.len(), 24);
/// assert_eq!(bits.elts(), 3);
/// assert_eq!(bits.bits(), 0);
/// assert!(bits.get(7)); // src[0] == 0b0000_0001
/// assert!(bits.get(14)); // src[1] == 0b0000_0010
/// assert!(bits.get(22)); // src[2] == 0b0000_0011
/// assert!(bits.get(23));
/// ```
fn from(src: &'a [T]) -> Self {

@@ -552,19 +594,23 @@ let (ptr, len): (*const T, usize) = (src.as_ptr(), src.len());

/// Builds a mutable `BitSlice` from a slice of mutable elements. The resulting
/// Build a mutable `BitSlice` from a slice of mutable elements. The resulting
/// `BitSlice` will always completely fill the original slice, and will not have
/// a partial tail.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut src = vec![1u8, 2, 3];
/// let borrow: &mut [u8] = &mut src;
/// let bits: &mut BitSlice = borrow.into();
/// assert!(!bits.get(0));
/// bits.set(0, true);
/// assert!(bits.get(0));
/// ```
impl<'a, E, T> From<&'a mut [T]> for &'a mut BitSlice<E, T>
where E: Endian, T: 'a + Bits {
/// Wrap an `&mut [T: Bits]` in an `&mut BitSlice<E: Endian, T>`. The
/// endianness must be specified by the call site. The element type cannot
/// be changed.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut src = vec![1u8, 2, 3];
/// let borrow: &mut [u8] = &mut src;
/// let bits: &mut BitSlice<LittleEndian, _> = borrow.into();
/// // The first bit read is the LSb of the first element, which is set.
/// assert!(bits.get(0));
/// bits.set(0, false);
/// assert!(!bits.get(0));
/// ```
fn from(src: &'a mut [T]) -> Self {

@@ -583,12 +629,2 @@ let (ptr, len): (*mut T, usize) = (src.as_mut_ptr(), src.len());

/// of the `BitSlice`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![0, 0, 1, 0, 0];
/// let bits: &BitSlice = &bv;
/// assert!(bits[2]);
/// assert!(!bits[3]);
/// ```
impl<'a, E, T> Index<usize> for &'a BitSlice<E, T>

@@ -598,2 +634,13 @@ where E: Endian, T: 'a + Bits {

/// Look up a single bit by semantic count.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![0, 0, 1, 0, 0];
/// let bits: &BitSlice = &bv;
/// assert!(bits[2]);
/// assert!(!bits[3]);
/// ```
fn index(&self, index: usize) -> &Self::Output {

@@ -611,12 +658,3 @@ match self.get(index) {

///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![0; 10];
/// bv.push(true);
/// let bits: &BitSlice = &bv;
/// assert!(bits[(1, 2)]); // 10
/// assert!(!bits[(1, 1)]); // 9
/// ```
/// This index is not recommended for public use.
impl<'a, E, T> Index<(usize, u8)> for &'a BitSlice<E, T>

@@ -626,2 +664,15 @@ where E: Endian, T: 'a + Bits {

/// Look up a single bit by storage element and bit indices. The bit index
/// is still a semantic count, not an absolute index into the element.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![0; 10];
/// bv.push(true);
/// let bits: &BitSlice = &bv;
/// assert!(bits[(1, 2)]); // 10
/// assert!(!bits[(1, 1)]); // 9
/// ```
fn index(&self, (elt, bit): (usize, u8)) -> &Self::Output {

@@ -635,3 +686,3 @@ match self.get(T::join(elt, bit)) {

/// Produces a read-only iterator over all the bits in the `BitSlice`.
/// Produce a read-only iterator over all the bits in the `BitSlice`.
///

@@ -646,2 +697,16 @@ /// This iterator follows the ordering in the `BitSlice` type, and implements

/// Iterate over the slice.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![1, 0, 1, 0, 1, 1, 0, 0];
/// let bref: &BitSlice = &bv;
/// let mut count = 0;
/// for bit in bref {
/// if bit { count += 1; }
/// }
/// assert_eq!(count, 4);
/// ```
fn into_iter(self) -> Self::IntoIter {

@@ -652,3 +717,3 @@ self.into()

/// Flips all bits in the slice, in place.
/// Flip all bits in the slice, in place.
///

@@ -658,16 +723,4 @@ /// This invokes the `!` operator on each element of the borrowed storage, and

/// if any. Use `^= repeat(true)` to flip only the bits actually inside the
/// `BitSlice` purview.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![0; 10];
/// let bits: &mut BitSlice = &mut bv;
/// let new_bits = !bits;
/// // The `bits` binding is consumed by the `!` operator, and a new reference
/// // is returned.
/// // assert_eq!(bits.as_ref(), &[!0, !0]);
/// assert_eq!(new_bits.as_ref(), &[!0, !0]);
/// ```
/// `BitSlice` purview. `^=` also has the advantage of being a borrowing
/// operator rather than a consuming/returning operator.
impl<'a, E, T> Not for &'a mut BitSlice<E, T>

@@ -677,2 +730,16 @@ where E: Endian, T: 'a + Bits {

/// Invert all bits in the slice.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![0; 10];
/// let bits: &mut BitSlice = &mut bv;
/// let new_bits = !bits;
/// // The `bits` binding is consumed by the `!` operator, and a new reference
/// // is returned.
/// // assert_eq!(bits.as_ref(), &[!0, !0]);
/// assert_eq!(new_bits.as_ref(), &[!0, !0]);
/// ```
fn not(self) -> Self::Output {

@@ -686,3 +753,3 @@ for elt in self.as_mut() {

/// Tests if two `BitSlice`s are semantically — not bitwise — equal.
/// Test if two `BitSlice`s are semantically — not bitwise — equal.
///

@@ -693,16 +760,17 @@ /// It is valid to compare two slices of different endianness or element types.

/// and that each pair of bits in semantic order are identical.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let l: BitVec<LittleEndian, u16> = bitvec![LittleEndian, u16; 0, 1, 0, 1];
/// let r: BitVec<BigEndian, u32> = bitvec![BigEndian, u32; 0, 1, 0, 1];
///
/// let ls: &BitSlice<_, _> = &l;
/// let rs: &BitSlice<_, _> = &r;
/// assert!(ls == rs);
/// ```
impl<A, B, C, D> PartialEq<BitSlice<C, D>> for BitSlice<A, B>
where A: Endian, B: Bits, C: Endian, D: Bits {
/// Perform a comparison by `==`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let l: BitVec<LittleEndian, u16> = bitvec![LittleEndian, u16; 0, 1, 0, 1];
/// let r: BitVec<BigEndian, u32> = bitvec![BigEndian, u32; 0, 1, 0, 1];
///
/// let ls: &BitSlice<_, _> = &l;
/// let rs: &BitSlice<_, _> = &r;
/// assert!(ls == rs);
/// ```
fn eq(&self, rhs: &BitSlice<C, D>) -> bool {

@@ -720,3 +788,3 @@ let (l, r) = (self.iter(), rhs.iter());

/// Compares two `BitSlice`s by semantic — not bitwise — ordering.
/// Compare two `BitSlice`s by semantic — not bitwise — ordering.
///

@@ -727,20 +795,21 @@ /// The comparison sorts by testing each index for one slice to have a set bit

///
/// If one of the slices is exhausted while the inspected part is identical,
/// then the slices sort by length.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let a = bitvec![0, 1, 0, 0];
/// let b = bitvec![0, 1, 0, 1];
/// let c = bitvec![0, 1, 0, 1, 1];
/// let aref: &BitSlice = &a;
/// let bref: &BitSlice = &b;
/// let cref: &BitSlice = &c;
/// assert!(aref < bref);
/// assert!(bref < cref);
/// ```
/// If one of the slices is exhausted before they differ, the longer slice is
/// greater.
impl<A, B, C, D> PartialOrd<BitSlice<C, D>> for BitSlice<A, B>
where A: Endian, B: Bits, C: Endian, D: Bits {
/// Perform a comparison by `<` or `>`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let a = bitvec![0, 1, 0, 0];
/// let b = bitvec![0, 1, 0, 1];
/// let c = bitvec![0, 1, 0, 1, 1];
/// let aref: &BitSlice = &a;
/// let bref: &BitSlice = &b;
/// let cref: &BitSlice = &c;
/// assert!(aref < bref);
/// assert!(bref < cref);
/// ```
fn partial_cmp(&self, rhs: &BitSlice<C, D>) -> Option<Ordering> {

@@ -770,3 +839,3 @@ for (l, r) in self.iter().zip(rhs.iter()) {

/// Shifts all bits in the array to the left — DOWN AND TOWARDS THE FRONT.
/// Shift all bits in the array to the left — DOWN AND TOWARDS THE FRONT.
///

@@ -800,15 +869,16 @@ /// On primitives, the left-shift operator `<<` moves bits away from the origin

/// A shift amount of zero is a no-op, and returns immediately.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![1, 1, 1, 0, 0, 0, 0, 0, 1];
/// let bits: &mut BitSlice = &mut bv;
/// *bits <<= 3;
/// assert_eq!("00000100 0", &format!("{}", bits));
/// // ^ former tail
/// ```
impl<E, T> ShlAssign<usize> for BitSlice<E, T>
where E: Endian, T: Bits {
/// Shift a slice left, in place.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![1, 1, 1, 0, 0, 0, 0, 0, 1];
/// let bits: &mut BitSlice = &mut bv;
/// *bits <<= 3;
/// assert_eq!("00000100 0", &format!("{}", bits));
/// // ^ former tail
/// ```
fn shl_assign(&mut self, shamt: usize) {

@@ -867,3 +937,3 @@ let len = self.len();

/// Shifts all bits in the array to the right — UP AND TOWARDS THE BACK.
/// Shift all bits in the array to the right — UP AND TOWARDS THE BACK.
///

@@ -897,15 +967,16 @@ /// On primitives, the right-shift operator `>>` moves bits towards the origin

/// A shift amount of zero is a no-op, and returns immediately.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![1, 0, 0, 0, 0, 0, 1, 1, 1];
/// let bits: &mut BitSlice = &mut bv;
/// *bits >>= 3;
/// assert_eq!("00010000 0", &format!("{}", bits));
/// // ^ former head
/// ```
impl<E, T> ShrAssign<usize> for BitSlice<E, T>
where E: Endian, T: Bits {
/// Shift a slice right, in place.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![1, 0, 0, 0, 0, 0, 1, 1, 1];
/// let bits: &mut BitSlice = &mut bv;
/// *bits >>= 3;
/// assert_eq!("00010000 0", &format!("{}", bits));
/// // ^ former head
/// ```
fn shr_assign(&mut self, shamt: usize) {

@@ -955,3 +1026,3 @@ let len = self.len();

/// Clones a borrowed `BitSlice` into an owned `BitVec`.
/// Clone a borrowed `BitSlice` into an owned `BitVec`.
impl<E, T> ToOwned for BitSlice<E, T>

@@ -961,2 +1032,11 @@ where E: Endian, T: Bits {

/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src = bitvec![0; 5];
/// let src_ref: &BitSlice = &src;
/// let dst = src_ref.to_owned();
/// assert_eq!(src, dst);
/// ```
fn to_owned(&self) -> Self::Owned {

@@ -969,2 +1049,3 @@ let mut out = Self::Owned::with_capacity(self.len());

ptr::copy_nonoverlapping(src, dst, len);
out.set_len(self.len());
}

@@ -975,3 +1056,3 @@ out

/// Permits iteration over a `BitSlice`
/// Permit iteration over a `BitSlice`
#[doc(hidden)]

@@ -978,0 +1059,0 @@ pub struct Iter<'a, E: 'a + Endian, T: 'a + Bits> {

+443
-345

@@ -15,2 +15,9 @@ use super::{

use std::clone::Clone;
use std::cmp::{
Eq,
Ord,
Ordering,
PartialEq,
PartialOrd,
};
use std::convert::{

@@ -88,3 +95,3 @@ AsMut,

where E: Endian, T: Bits {
/// Constructs a new, empty, `BitVec<E, T>`.
/// Construct a new, empty, `BitVec<E, T>`.
///

@@ -108,3 +115,3 @@ /// The vector will not allocate until bits are pushed onto it.

/// Constructs a new, empty `BitVec<T>` with the specified capacity.
/// Construct a new, empty `BitVec<T>` with the specified capacity.
///

@@ -131,3 +138,3 @@ /// The vector will be able to hold exactly `capacity` elements without

/// Returns the number of bits the vector can hold without reallocating.
/// Return the number of bits the vector can hold without reallocating.
///

@@ -147,3 +154,3 @@ /// # Examples

/// Appends a bit to the collection.
/// Append a bit to the collection.
///

@@ -178,3 +185,3 @@ /// # Examples

/// Removes the last bit from the collection.
/// Remove the last bit from the collection.
///

@@ -210,23 +217,2 @@ /// Returns `None` if the collection is empty.

/// Returns a borrowing, read-only, iterator over the underlying `BitSlice`.
///
/// It is impossible to create an iterator that yields mutable references to
/// bits, so there is no corresponding `iter_mut` function.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![0, 1, 0, 1, 0];
/// let mut iter = bv.iter();
/// for bit in iter {
/// print!("{} ", bit as u8);
/// }
/// println!();
/// //> prints "0 1 0 1 0"
/// ```
pub fn iter(&self) -> <&BitSlice<E, T> as IntoIterator>::IntoIter {
(&*self as &BitSlice<E, T>).into_iter()
}
/// Empty out the `BitVec`, resetting it to length zero.

@@ -333,3 +319,3 @@ ///

/// Sets the bit count to a new value.
/// Set the bit count to a new value.
///

@@ -345,3 +331,3 @@ /// This utility function unconditionally sets the bottom `T::BITS` bits of

/// Sets the element count to a new value.
/// Set the element count to a new value.
///

@@ -360,18 +346,8 @@ /// This utility function unconditionally sets the rest of the bits of

/// Set the length directly.
unsafe fn set_len(&mut self, len: usize) {
pub(crate) unsafe fn set_len(&mut self, len: usize) {
self.inner.set_len(len);
}
/// The actual number of live elements in the underlying store.
/// Execute some operation with the storage `Vec` in sane condition.
///
/// If `bits()` is 0, then the cursor is hovering over non-live memory, and
/// all the elements are full, so `elts()` is correct. If `bits()` is
/// non-zero, then a partial element exists about which `elts()` does not
/// know, and must be added.
fn raw_len(&self) -> usize {
self.elts() + if self.bits() > 0 { 1 } else { 0 }
}
/// Executes some operation with the storage `Vec` in sane condition.
///
/// The given function receives a sane `Vec<T>`, with the `len` attribute

@@ -408,5 +384,2 @@ /// set to reflect the reality of elements in use. The storage `Vec` is then

assert!(new <= T::MAX_ELT, "Length out of range!");
if new == old + 1 {
eprintln!("Did you just call `Vec.push` in `do_with_vec`? Don't do that! Use `BitVec.push_elt`.");
}
// If the length is unchanged before and after the call, restore the

@@ -430,3 +403,3 @@ // original bit length.

/// Executes some operation with the tail storage element.
/// Execute some operation with the tail storage element.
///

@@ -468,61 +441,50 @@ /// If the bit cursor is at zero when this is called, then the current tail

/// Formats the debug header for the type
/// Format the debug header for the type.
///
/// The body format is provided by `BitSlice`.
fn fmt_header(&self, fmt: &mut Formatter) -> fmt::Result {
// write!(fmt, "BitVec<{}, {}> {{ ptr: {:p}, len_bits: {}, cap_elts: {} }} [",
write!(fmt, "BitVec<{}, {}>",
E::TY,
T::TY,
// self.inner.as_ptr(),
// self.inner.len(),
// self.inner.capacity(),
)
write!(fmt, "BitVec<{}, {}>", E::TY, T::TY)
}
}
/// Gives write access to all live elements in the underlying storage, including
/// Give write access to all live elements in the underlying storage, including
/// the partially-filled tail.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src: &[u8] = &[5, 10, 15, 20, 25];
/// let mut bv: BitVec = src.into();
/// for elt in bv.as_mut() {
/// *elt += 2;
/// }
/// assert_eq!(&[7, 12, 17, 22, 27], bv.as_ref());
/// ```
impl<E, T> AsMut<[T]> for BitVec<E, T>
where E: Endian, T: Bits {
/// Access the underlying store.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv: BitVec = bitvec![0, 0, 0, 0, 0, 0, 0, 0, 1];
/// for elt in bv.as_mut() {
/// *elt += 2;
/// }
/// assert_eq!(&[2, 0b1000_0010], bv.as_ref());
/// ```
fn as_mut(&mut self) -> &mut [T] {
let ptr = self.inner.as_ptr() as *mut T;
let raw = self.raw_len();
unsafe { ::std::slice::from_raw_parts_mut(ptr, raw) }
BitSlice::as_mut(self)
}
}
/// Gives read access to all live elements in the underlying storage, including
/// Give read access to all live elements in the underlying storage, including
/// the partially-filled tail.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src: &[u8] = &[5, 10, 15, 20, 25];
/// let bv: BitVec = src.into();
/// assert_eq!(&[5, 10, 15, 20, 25], bv.as_ref());
/// ```
impl<E, T> AsRef<[T]> for BitVec<E, T>
where E: Endian, T: Bits {
/// Access the underlying store.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![0, 0, 0, 0, 0, 0, 0, 0, 1];
/// assert_eq!(&[0, 0b1000_0000], bv.as_ref());
/// ```
fn as_ref(&self) -> &[T] {
let ptr = self.inner.as_ptr();
let raw = self.raw_len();
unsafe { ::std::slice::from_raw_parts(ptr, raw) }
BitSlice::as_ref(self)
}
}
/// Performs the Boolean AND operation between each element of a `BitVec` and
/// Perform the Boolean AND operation between each element of a `BitVec` and
/// anything that can provide a stream of `bool` values (such as another

@@ -532,12 +494,2 @@ /// `BitVec`, or any `bool` generator of your choice). The `BitVec` emitted will

/// other, the extra bits will be ignored.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// let rhs = bitvec![BigEndian, u8; 0, 0, 1, 1];
/// let and = lhs & rhs;
/// assert_eq!("0001", &format!("{}", and));
/// ```
impl<E, T, I> BitAnd<I> for BitVec<E, T>

@@ -547,2 +499,13 @@ where E: Endian, T: Bits, I: IntoIterator<Item=bool> {

/// AND a vector and a bitstream, producing a new vector.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// let rhs = bitvec![BigEndian, u8; 0, 0, 1, 1];
/// let and = lhs & rhs;
/// assert_eq!("0001", &format!("{}", and));
/// ```
fn bitand(mut self, rhs: I) -> Self::Output {

@@ -554,16 +517,17 @@ self &= rhs;

/// Performs the Boolean AND operation in place on a `BitVec`, using a stream of
/// Perform the Boolean AND operation in place on a `BitVec`, using a stream of
/// `bool` values as the other bit for each operation. If the other stream is
/// shorter than `self`, `self` will be truncated when the other stream expires.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut src = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// src &= bitvec![BigEndian, u8; 0, 0, 1, 1];
/// assert_eq!("0001", &format!("{}", src));
/// ```
impl<E, T, I> BitAndAssign<I> for BitVec<E, T>
where E: Endian, T: Bits, I: IntoIterator<Item=bool> {
/// AND another bitstream into a vector.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut src = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// src &= bitvec![BigEndian, u8; 0, 0, 1, 1];
/// assert_eq!("0001", &format!("{}", src));
/// ```
fn bitand_assign(&mut self, rhs: I) {

@@ -580,3 +544,3 @@ let mut len = 0;

/// Performs the Boolean OR operation between each element of a `BitVec` and
/// Perform the Boolean OR operation between each element of a `BitVec` and
/// anything that can provide a stream of `bool` values (such as another

@@ -586,12 +550,2 @@ /// `BitVec`, or any `bool` generator of your choice). The `BitVec` emitted will

/// other, the extra bits will be ignored.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// let rhs = bitvec![BigEndian, u8; 0, 0, 1, 1];
/// let or = lhs | rhs;
/// assert_eq!("0111", &format!("{}", or));
/// ```
impl<E, T, I> BitOr<I> for BitVec<E, T>

@@ -601,2 +555,13 @@ where E: Endian, T: Bits, I: IntoIterator<Item=bool> {

/// OR a vector and a bitstream, producing a new vector.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// let rhs = bitvec![BigEndian, u8; 0, 0, 1, 1];
/// let or = lhs | rhs;
/// assert_eq!("0111", &format!("{}", or));
/// ```
fn bitor(mut self, rhs: I) -> Self::Output {

@@ -608,16 +573,17 @@ self |= rhs;

/// Performs the Boolean OR operation in place on a `BitVec`, using a stream of
/// Perform the Boolean OR operation in place on a `BitVec`, using a stream of
/// `bool` values as the other bit for each operation. If the other stream is
/// shorter than `self`, `self` will be truncated when the other stream expires.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut src = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// src |= bitvec![BigEndian, u8; 0, 0, 1, 1];
/// assert_eq!("0111", &format!("{}", src));
/// ```
impl<E, T, I> BitOrAssign<I> for BitVec<E, T>
where E: Endian, T: Bits, I: IntoIterator<Item=bool> {
/// OR another bitstream into a vector.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut src = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// src |= bitvec![BigEndian, u8; 0, 0, 1, 1];
/// assert_eq!("0111", &format!("{}", src));
/// ```
fn bitor_assign(&mut self, rhs: I) {

@@ -634,3 +600,3 @@ let mut len = 0;

/// Performs the Boolean XOR operation between each element of a `BitVec` and
/// Perform the Boolean XOR operation between each element of a `BitVec` and
/// anything that can provide a stream of `bool` values (such as another

@@ -640,12 +606,2 @@ /// `BitVec`, or any `bool` generator of your choice). The `BitVec` emitted will

/// other, the extra bits will be ignored.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// let rhs = bitvec![BigEndian, u8; 0, 0, 1, 1];
/// let xor = lhs ^ rhs;
/// assert_eq!("0110", &format!("{}", xor));
/// ```
impl<E, T, I> BitXor<I> for BitVec<E, T>

@@ -655,2 +611,13 @@ where E: Endian, T: Bits, I: IntoIterator<Item=bool> {

/// XOR a vector and a bitstream, producing a new vector.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let lhs = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// let rhs = bitvec![BigEndian, u8; 0, 0, 1, 1];
/// let xor = lhs ^ rhs;
/// assert_eq!("0110", &format!("{}", xor));
/// ```
fn bitxor(mut self, rhs: I) -> Self::Output {

@@ -662,16 +629,17 @@ self ^= rhs;

/// Performs the Boolean XOR operation in place on a `BitVec`, using a stream of
/// Perform the Boolean XOR operation in place on a `BitVec`, using a stream of
/// `bool` values as the other bit for each operation. If the other stream is
/// shorter than `self`, `self` will be truncated when the other stream expires.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut src = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// src ^= bitvec![BigEndian, u8; 0, 0, 1, 1];
/// assert_eq!("0110", &format!("{}", src));
/// ```
impl<E, T, I> BitXorAssign<I> for BitVec<E, T>
where E: Endian, T: Bits, I: IntoIterator<Item=bool> {
/// XOR another bitstream into a vector.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut src = bitvec![BigEndian, u8; 0, 1, 0, 1];
/// src ^= bitvec![BigEndian, u8; 0, 0, 1, 1];
/// assert_eq!("0110", &format!("{}", src));
/// ```
fn bitxor_assign(&mut self, rhs: I) {

@@ -688,6 +656,16 @@ let mut len = 0;

/// Signifies that `BitSlice` is the borrowed form of `BitVec`.
/// Signify that `BitSlice` is the borrowed form of `BitVec`.
impl<E, T> Borrow<BitSlice<E, T>> for BitVec<E, T>
where E: Endian, T: Bits {
/// Borrows the `BitVec` as a `BitSlice`.
/// Borrow the `BitVec` as a `BitSlice`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// use std::borrow::Borrow;
/// let bv = bitvec![0; 8];
/// let bref: &BitSlice = bv.borrow();
/// assert!(!bref.get(7));
/// ```
fn borrow(&self) -> &BitSlice<E, T> {

@@ -698,6 +676,18 @@ &*self

/// Signifies that `BitSlice` is the borrowed form of `BitVec`.
/// Signify that `BitSlice` is the borrowed form of `BitVec`.
impl<E, T> BorrowMut<BitSlice<E, T>> for BitVec<E, T>
where E: Endian, T: Bits {
/// Mutably borows the `BitVec` as a `BitSlice`.
/// Mutably borow the `BitVec` as a `BitSlice`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// use std::borrow::BorrowMut;
/// let mut bv = bitvec![0; 8];
/// let bref: &mut BitSlice = bv.borrow_mut();
/// assert!(!bref.get(7));
/// bref.set(7, true);
/// assert!(bref.get(7));
/// ```
fn borrow_mut(&mut self) -> &mut BitSlice<E, T> {

@@ -730,3 +720,3 @@ &mut *self

/// Prints the `BitVec` for debugging.
/// Print the `BitVec` for debugging.
///

@@ -741,12 +731,18 @@ /// The output is of the form `BitVec<E, T> [ELT, *]`, where `<E, T>` is the

/// than separated by a space.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![LittleEndian, u16; 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1];
/// assert_eq!("BitVec<LittleEndian, u16> [0101000011110101]", &format!("{:?}", bv));
/// ```
impl<E, T> Debug for BitVec<E, T>
where E: Endian, T: Bits {
/// Render the `BitVec` type header and contents for debug.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![LittleEndian, u16;
/// 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1
/// ];
/// assert_eq!(
/// "BitVec<LittleEndian, u16> [0101000011110101]",
/// &format!("{:?}", bv)
/// );
/// ```
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {

@@ -770,2 +766,12 @@ let alt = fmt.alternate();

/// Dereference `&BitVec` down to `&BitSlice`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv: BitVec = bitvec![1; 4];
/// let bref: &BitSlice = &bv;
/// assert!(bref.get(2));
/// ```
fn deref(&self) -> &Self::Target {

@@ -783,2 +789,14 @@ // `BitVec`'s representation of its inner `Vec` matches exactly the

where E: Endian, T: Bits {
/// Dereference `&mut BitVec` down to `&mut BitSlice`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv: BitVec = bitvec![0; 6];
/// let bref: &mut BitSlice = &mut bv;
/// assert!(!bref.get(5));
/// bref.set(5, true);
/// assert!(bref.get(5));
/// ```
fn deref_mut(&mut self) -> &mut Self::Target {

@@ -789,3 +807,3 @@ unsafe { mem::transmute(&mut self.inner as &mut [T]) }

/// Prints the `BitVec` for displaying.
/// Print the `BitVec` for displaying.
///

@@ -800,12 +818,13 @@ /// This prints each element in turn, formatted in binary in semantic order (so

/// elements and print that slice instead.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 0, 1, 0, 0, 1, 0, 1, 1, 0, 1];
/// assert_eq!("01001011 01", &format!("{}", bv));
/// ```
impl<E, T> Display for BitVec<E, T>
where E: Endian, T: Bits {
/// Render the `BitVec` contents for display.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 0, 1, 0, 0, 1, 0, 1, 1, 0, 1];
/// assert_eq!("01001011 01", &format!("{}", bv));
/// ```
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {

@@ -816,3 +835,3 @@ self.fmt_body(fmt, false)

/// Readies the underlying storage for Drop.
/// Ready the underlying storage for Drop.
impl<E, T> Drop for BitVec<E, T>

@@ -838,13 +857,14 @@ where E: Endian, T: Bits {

/// source into `self` when the source is `BitSlice`-compatible.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![0; 4];
/// bv.extend(bitvec![1; 4]);
/// assert_eq!("00001111", &format!("{}", bv));
/// ```
impl<E, T> Extend<bool> for BitVec<E, T>
where E: Endian, T: Bits {
/// Extend a `BitVec` from another bitstream.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![0; 4];
/// bv.extend(bitvec![1; 4]);
/// assert_eq!("00001111", &format!("{}", bv));
/// ```
fn extend<I>(&mut self, src: I)

@@ -864,3 +884,6 @@ where I: IntoIterator<Item=bool> {

/// Clones a `BitSlice` into an owned `BitVec`.
/// Clone a `BitSlice` into an owned `BitVec`.
///
/// The idiomatic `BitSlice` to `BitVec` conversion is `BitSlice::to_owned`, but
/// just as `&[T].into()` yields a `Vec`, `&BitSlice.into()` yields a `BitVec`.
impl<'a, E, T> From<&'a BitSlice<E, T>> for BitVec<E, T>

@@ -873,3 +896,6 @@ where E: Endian, T: 'a + Bits {

/// Builds a `BitVec` out of a slice of `bool`.
/// Build a `BitVec` out of a slice of `bool`.
///
/// This is primarily for the `bitvec!` macro; it is not recommended for general
/// use.
impl<'a, E, T> From<&'a [bool]> for BitVec<E, T>

@@ -890,26 +916,20 @@ where E: Endian, T: 'a + Bits {

/// The source buffer will be unchanged by this operation, so you don't need to
/// worry about using the correct cursor type.
/// worry about using the correct cursor type for the read.
///
/// This operation does a copy from the source buffer into a new allocation, as
/// it can only borrow the source and not take ownership.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src: &[u8] = &[5, 10];
/// let bv: BitVec = src.into();
/// assert_eq!("00000101 00001010", &format!("{}", bv));
impl<'a, E, T> From<&'a [T]> for BitVec<E, T>
where E: Endian, T: 'a + Bits {
/// Build a `BitVec<E: Endian, T: Bits>` from a borrowed `&[T]`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src: &[u8] = &[5, 10];
/// let bv: BitVec = src.into();
/// assert_eq!("00000101 00001010", &format!("{}", bv));
/// ```
fn from(src: &'a [T]) -> Self {
use std::ptr::copy_nonoverlapping;
let len = src.len();
assert!(len <= T::MAX_ELT, "Source slice too long!");
let mut out = Self::with_capacity(len << T::BITS);
out.do_with_vec(|v| unsafe {
copy_nonoverlapping(src.as_ptr(), v.as_ptr() as *mut T, len);
v.set_len(len);
});
out
<&BitSlice<E, T>>::from(src).to_owned()
}

@@ -923,13 +943,14 @@ }

/// worry about using the correct cursor type.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src: Box<[u8]> = Box::new([3, 6, 9, 12, 15]);
/// let bv: BitVec = src.into();
/// assert_eq!("00000011 00000110 00001001 00001100 00001111", &format!("{}", bv));
/// ```
impl<E, T> From<Box<[T]>> for BitVec<E, T>
where E: Endian, T: Bits {
/// Consume a `Box<[T: Bits]>` and creates a `BitVec<E: Endian, T>` from it.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src: Box<[u8]> = Box::new([3, 6, 9, 12, 15]);
/// let bv: BitVec = src.into();
/// assert_eq!("00000011 00000110 00001001 00001100 00001111", &format!("{}", bv));
/// ```
fn from(src: Box<[T]>) -> Self {

@@ -946,13 +967,14 @@ assert!(src.len() <= T::MAX_ELT, "Source slice too long!");

/// worry about using the correct cursor type.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src: Vec<u8> = vec![1, 2, 4, 8];
/// let bv: BitVec = src.into();
/// assert_eq!("00000001 00000010 00000100 00001000", &format!("{}", bv));
/// ```
impl<E, T> From<Vec<T>> for BitVec<E, T>
where E: Endian, T: Bits {
/// Consume a `Vec<T: Bits>` and creates a `BitVec<E: Endian, T>` from it.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let src: Vec<u8> = vec![1, 2, 4, 8];
/// let bv: BitVec = src.into();
/// assert_eq!("00000001 00000010 00000100 00001000", &format!("{}", bv));
/// ```
fn from(src: Vec<T>) -> Self {

@@ -1023,15 +1045,16 @@ let elts = src.len();

/// Permits the construction of a `BitVec` by using `.collect()` on an iterator
/// of `bool`
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// use std::iter::repeat;
/// let bv: BitVec = repeat(true).take(4).chain(repeat(false).take(4)).collect();
/// assert_eq!("11110000", &format!("{}", bv));
/// ```
/// Permit the construction of a `BitVec` by using `.collect()` on an iterator
/// of `bool`.
impl<E, T> FromIterator<bool> for BitVec<E, T>
where E: Endian, T: Bits {
/// Collect an iterator of `bool` into a vector.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// use std::iter::repeat;
/// let bv: BitVec = repeat(true).take(4).chain(repeat(false).take(4)).collect();
/// assert_eq!("11110000", &format!("{}", bv));
/// ```
fn from_iter<I: IntoIterator<Item=bool>>(src: I) -> Self {

@@ -1053,23 +1076,2 @@ let iter = src.into_iter();

/// the `BitVec`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 0, 0, 0, 0, 0, 0, 0, 0, 1, 0];
/// assert!(!bv[7]); // ---------------------------------^ | |
/// assert!( bv[8]); //-------------------------------------^ |
/// assert!(!bv[9]); // ---------------------------------------^
/// ```
///
/// If the index is greater than or equal to the length, indexing will panic.
///
/// The below test will panic when accessing index 1, as only index 0 is valid.
///
/// ```rust,should_panic
/// use bitvec::*;
/// let mut bv: BitVec = BitVec::new();
/// bv.push(true);
/// bv[1];
/// ```
impl<E, T> Index<usize> for BitVec<E, T>

@@ -1079,2 +1081,24 @@ where E: Endian, T: Bits {

/// Look up a single bit by semantic count.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 0, 0, 0, 0, 0, 0, 0, 0, 1, 0];
/// assert!(!bv[7]); // ---------------------------------^ | |
/// assert!( bv[8]); //-------------------------------------^ |
/// assert!(!bv[9]); // ---------------------------------------^
/// ```
///
/// If the index is greater than or equal to the length, indexing will panic.
///
/// The below test will panic when accessing index 1, as only index 0 is valid.
///
/// ```rust,should_panic
/// use bitvec::*;
/// let mut bv: BitVec = BitVec::new();
/// bv.push(true);
/// bv[1];
/// ```
fn index(&self, cursor: usize) -> &Self::Output {

@@ -1096,9 +1120,3 @@ assert!(cursor < self.inner.len(), "Index out of range!");

///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 1, 1, 1, 1, 0, 0, 0, 0, 0, 1];
/// assert!(bv[(1, 1)]); // -----------------------------------^
/// ```
/// This index is not recommended for public use.
impl<E, T> Index<(usize, u8)> for BitVec<E, T>

@@ -1109,3 +1127,12 @@ where E: Endian, T: Bits {

/// Index into a `BitVec` using a known element index and a count into that
/// element. The count must not be converted for endianness outside the call
/// element. The count must not be converted for endianness outside the
/// call.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 1, 1, 1, 1, 0, 0, 0, 0, 0, 1];
/// assert!(bv[(1, 1)]); // -----------------------------------^
/// ```
fn index(&self, (elt, bit): (usize, u8)) -> &Self::Output {

@@ -1120,3 +1147,3 @@ assert!(T::join(elt, bit) < self.len(), "Index out of range!");

/// Produces an iterator over all the bits in the vector.
/// Produce an iterator over all the bits in the vector.
///

@@ -1126,14 +1153,2 @@ /// This iterator follows the ordering in the vector type, and implements

/// and `DoubleEndedIterator`, since they have known ends.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 1, 1, 1, 1, 0, 0, 0, 0];
/// let mut count = 0;
/// for bit in bv {
/// if bit { count += 1; }
/// }
/// assert_eq!(count, 4);
/// ```
impl<E, T> IntoIterator for BitVec<E, T>

@@ -1145,2 +1160,15 @@ where E: Endian, T: Bits {

/// Iterate over the vector.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 1, 1, 1, 1, 0, 0, 0, 0];
/// let mut count = 0;
/// for bit in bv {
/// if bit { count += 1; }
/// }
/// assert_eq!(count, 4);
/// ```
fn into_iter(self) -> Self::IntoIter {

@@ -1151,11 +1179,9 @@ Self::IntoIter::from(self)

/// Flips all bits in the vector.
/// Flip all bits in the vector.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv: BitVec<BigEndian, u32> = BitVec::from(&[0u32] as &[u32]);
/// let flip = !bv;
/// assert_eq!(!0u32, flip.as_ref()[0]);
/// This invokes the `!` operator on each element of the borrowed storage, and
/// so it will also flip bits in the tail that are outside the `BitVec` length
/// if any. Use `^= repeat(true)` to flip only the bits actually inside the
/// `BitVec` purview. `^=` also has the advantage of being a borrowing operator
/// rather than a consuming/returning operator.
/// ```

@@ -1166,2 +1192,11 @@ impl<E, T> Not for BitVec<E, T>

/// Invert all bits in the vector.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv: BitVec<BigEndian, u32> = BitVec::from(&[0u32] as &[u32]);
/// let flip = !bv;
/// assert_eq!(!0u32, flip.as_ref()[0]);
// Because self does not have to interact with any other `BitVec`, and bits

@@ -1171,5 +1206,3 @@ // beyond `BitVec.len()` are uninitialized and don't matter, this is free

fn not(mut self) -> Self::Output {
for elt in self.as_mut() {
*elt = !*elt;
}
!&mut *self;
self

@@ -1179,5 +1212,66 @@ }

/// Test if two `BitVec`s are semantically — not bitwise — equal.
///
/// It is valid to compare two vectors of different endianness or element types.
///
/// The equality condition requires that they have the same number of stored
/// bits and that each pair of bits in semantic order are identical.
impl<A, B, C, D> PartialEq<BitVec<C, D>> for BitVec<A, B>
where A: Endian, B: Bits, C: Endian, D: Bits {
/// Perform a comparison by `==`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let l: BitVec<LittleEndian, u16> = bitvec![LittleEndian, u16; 0, 1, 0, 1];
/// let r: BitVec<BigEndian, u32> = bitvec![BigEndian, u32; 0, 1, 0, 1];
/// assert!(l == r);
/// ```
fn eq(&self, rhs: &BitVec<C, D>) -> bool {
BitSlice::eq(&self, &rhs)
}
}
impl<E, T> Eq for BitVec<E, T>
where E: Endian, T: Bits {}
/// Compare two `BitVec`s by semantic — not bitwise — ordering.
///
/// The comparison sorts by testing each index for one vector to have a set bit
/// where the other vector has an unset bit. If the vectors are different, the
/// vector with the set bit sorts greater than the vector with the unset bit.
///
/// If one of the vectors is exhausted before they differ, the longer vector is
/// greater.
impl<A, B, C, D> PartialOrd<BitVec<C, D>> for BitVec<A, B>
where A: Endian, B: Bits, C: Endian, D: Bits {
/// Perform a comparison by `<` or `>`.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// use bitvec::*;
/// let a = bitvec![0, 1, 0, 0];
/// let b = bitvec![0, 1, 0, 1];
/// let c = bitvec![0, 1, 0, 1, 1];
/// assert!(a < b);
/// assert!(b < c);
/// ```
fn partial_cmp(&self, rhs: &BitVec<C, D>) -> Option<Ordering> {
BitSlice::partial_cmp(&self, &rhs)
}
}
impl<E, T> Ord for BitVec<E, T>
where E: Endian, T: Bits {
fn cmp(&self, rhs: &Self) -> Ordering {
BitSlice::cmp(&self, &rhs)
}
}
__bitvec_shift!(u8, u16, u32, u64, i8, i16, i32, i64);
/// Shifts all bits in the vector to the left – DOWN AND TOWARDS THE FRONT.
/// Shift all bits in the vector to the left – DOWN AND TOWARDS THE FRONT.
///

@@ -1210,16 +1304,2 @@ /// On primitives, the left-shift operator `<<` moves bits away from origin and

/// and zeroes its memory. This is *not* an error.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 0, 0, 0, 1, 1, 1];
/// assert_eq!("000111", &format!("{}", bv));
/// assert_eq!(0b0001_1100, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 6);
/// let ls = bv << 2usize;
/// assert_eq!("0111", &format!("{}", ls));
/// assert_eq!(0b0111_0000, ls.as_ref()[0]);
/// assert_eq!(ls.len(), 4);
/// ```
impl<E, T> Shl<usize> for BitVec<E, T>

@@ -1229,2 +1309,17 @@ where E: Endian, T: Bits {

/// Shift a `BitVec` to the left, shortening it.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 0, 0, 0, 1, 1, 1];
/// assert_eq!("000111", &format!("{}", bv));
/// assert_eq!(0b0001_1100, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 6);
/// let ls = bv << 2usize;
/// assert_eq!("0111", &format!("{}", ls));
/// assert_eq!(0b0111_0000, ls.as_ref()[0]);
/// assert_eq!(ls.len(), 4);
/// ```
fn shl(mut self, shamt: usize) -> Self::Output {

@@ -1236,3 +1331,3 @@ self <<= shamt;

/// Shifts all bits in the vector to the left – DOWN AND TOWARDS THE FRONT.
/// Shift all bits in the vector to the left – DOWN AND TOWARDS THE FRONT.
///

@@ -1265,18 +1360,19 @@ /// On primitives, the left-shift operator `<<` moves bits away from origin and

/// and zeroes its memory. This is *not* an error.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![LittleEndian, u8; 0, 0, 0, 1, 1, 1];
/// assert_eq!("000111", &format!("{}", bv));
/// assert_eq!(0b0011_1000, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 6);
/// bv <<= 2;
/// assert_eq!("0111", &format!("{}", bv));
/// assert_eq!(0b0000_1110, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 4);
/// ```
impl<E, T> ShlAssign<usize> for BitVec<E, T>
where E: Endian, T: Bits {
/// Shift a `BitVec` to the left in place, shortening it.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![LittleEndian, u8; 0, 0, 0, 1, 1, 1];
/// assert_eq!("000111", &format!("{}", bv));
/// assert_eq!(0b0011_1000, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 6);
/// bv <<= 2;
/// assert_eq!("0111", &format!("{}", bv));
/// assert_eq!(0b0000_1110, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 4);
/// ```
fn shl_assign(&mut self, shamt: usize) {

@@ -1304,3 +1400,3 @@ let len = self.len();

/// Shifts all bits in the vector to the right – UP AND TOWARDS THE BACK.
/// Shift all bits in the vector to the right – UP AND TOWARDS THE BACK.
///

@@ -1334,16 +1430,2 @@ /// On primitives, the right-shift operator `>>` moves bits towards the origin

/// error.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 0, 0, 0, 1, 1, 1];
/// assert_eq!("000111", &format!("{}", bv));
/// assert_eq!(0b0001_1100, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 6);
/// let rs = bv >> 2usize;
/// assert_eq!("00000111", &format!("{}", rs));
/// assert_eq!(0b0000_0111, rs.as_ref()[0]);
/// assert_eq!(rs.len(), 8);
/// ```
impl<E, T> Shr<usize> for BitVec<E, T>

@@ -1353,2 +1435,17 @@ where E: Endian, T: Bits {

/// Shift a `BitVec` to the right, lengthening it and filling the front with 0.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let bv = bitvec![BigEndian, u8; 0, 0, 0, 1, 1, 1];
/// assert_eq!("000111", &format!("{}", bv));
/// assert_eq!(0b0001_1100, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 6);
/// let rs = bv >> 2usize;
/// assert_eq!("00000111", &format!("{}", rs));
/// assert_eq!(0b0000_0111, rs.as_ref()[0]);
/// assert_eq!(rs.len(), 8);
/// ```
fn shr(mut self, shamt: usize) -> Self::Output {

@@ -1360,3 +1457,3 @@ self >>= shamt;

/// Shifts all bits in the vector to the right – UP AND TOWARDS THE BACK.
/// Shift all bits in the vector to the right – UP AND TOWARDS THE BACK.
///

@@ -1390,18 +1487,20 @@ /// On primitives, the right-shift operator `>>` moves bits towards the origin

/// error.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![LittleEndian, u8; 0, 0, 0, 1, 1, 1];
/// assert_eq!("000111", &format!("{}", bv));
/// assert_eq!(0b0011_1000, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 6);
/// bv >>= 2;
/// assert_eq!("00000111", &format!("{}", bv));
/// assert_eq!(0b1110_0000, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 8);
/// ```
impl<E, T> ShrAssign<usize> for BitVec<E, T>
where E: Endian, T: Bits {
/// Shift a `BitVec` to the right in place, lengthening it and filling the
/// front with 0.
///
/// # Examples
///
/// ```rust
/// use bitvec::*;
/// let mut bv = bitvec![LittleEndian, u8; 0, 0, 0, 1, 1, 1];
/// assert_eq!("000111", &format!("{}", bv));
/// assert_eq!(0b0011_1000, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 6);
/// bv >>= 2;
/// assert_eq!("00000111", &format!("{}", bv));
/// assert_eq!(0b1110_0000, bv.as_ref()[0]);
/// assert_eq!(bv.len(), 8);
/// ```
fn shr_assign(&mut self, shamt: usize) {

@@ -1423,3 +1522,3 @@ let old_len = self.len();

/// Iterates over an owned `BitVec`.
/// Iterate over an owned `BitVec`.
#[doc(hidden)]

@@ -1498,3 +1597,3 @@ pub struct IntoIter<E, T>

/// Advances the iterator forward, yielding the front-most bit.
/// Advance the iterator forward, yielding the front-most bit.
///

@@ -1512,3 +1611,2 @@ /// This iterator is self-resetting: when the cursor reaches the back of the

else {
eprintln!("{} >= {}", self.head, self.tail);
self.reset();

@@ -1532,3 +1630,3 @@ None

/// Counts how many bits are live in the iterator, consuming it.
/// Count how many bits are live in the iterator, consuming it.
///

@@ -1549,3 +1647,3 @@ /// You are probably looking to use this on a borrowed iterator rather than

/// Advances the iterator by `n` bits, starting from zero.
/// Advance the iterator by `n` bits, starting from zero.
///

@@ -1585,3 +1683,3 @@ /// It is not an error to advance past the end of the iterator! Doing so

/// Consumes the iterator, returning only the last bit.
/// Consume the iterator, returning only the last bit.
///

@@ -1588,0 +1686,0 @@ /// # Examples

Sorry, the diff of this file is not supported yet