| # Code of Conduct | ||
| See the official [Rust code of conduct][0]. | ||
| [0]: https://www.rust-lang.org/conduct.html |
| /*! Prove that the example code in `README.md` executes. | ||
| !*/ | ||
| #[cfg(feature = "alloc")] | ||
| extern crate bitvec; | ||
| #[cfg(feature = "alloc")] | ||
| use bitvec::*; | ||
| #[cfg(feature = "alloc")] | ||
| use std::iter::repeat; | ||
| #[cfg(feature = "alloc")] | ||
| fn main() { | ||
| let mut bv = bitvec![BigEndian, u8; 0, 1, 0, 1]; | ||
| bv.reserve(8); | ||
| bv.extend(repeat(false).take(4).chain(repeat(true).take(4))); | ||
| // Memory access | ||
| assert_eq!(bv.as_ref(), &[0b0101_0000, 0b1111_0000]); | ||
| // index 0 -^ ^- index 11 | ||
| assert_eq!(bv.len(), 12); | ||
| assert!(bv.capacity() >= 16); | ||
| // Set operations | ||
| bv &= repeat(true); | ||
| bv = bv | repeat(false); | ||
| bv ^= repeat(true); | ||
| bv = !bv; | ||
| // Arithmetic operations | ||
| let one = bitvec![1]; | ||
| bv += one.clone(); | ||
| assert_eq!(bv.as_ref(), &[0b0101_0001, 0b0000_0000]); | ||
| bv -= one.clone(); | ||
| assert_eq!(bv.as_ref(), &[0b0101_0000, 0b1111_0000]); | ||
| // Borrowing iteration | ||
| let mut iter = bv.iter(); | ||
| // index 0 | ||
| assert_eq!(iter.next().unwrap(), false); | ||
| // index 11 | ||
| assert_eq!(iter.next_back().unwrap(), true); | ||
| assert_eq!(iter.len(), 10); | ||
| } | ||
| #[cfg(not(feature = "alloc"))] | ||
| fn main() { | ||
| println!("This example only runs when an allocator is present"); | ||
| } |
+34
| # Development Notes | ||
| ## Features | ||
| By default, this crate assumes `std` is present, and links against it. | ||
| `#![no_std]` can be turned on by disabling default features and enabling the | ||
| `alloc` feature, with either the `--features=alloc` Cargo flag or the | ||
| ```toml | ||
| [dependencies.bitvec] | ||
| version = "*" | ||
| default-features = false | ||
| features = ["alloc"] | ||
| ``` | ||
| configuration. | ||
| The `alloc` feature links agains the `alloc` crate, and changes the symbol | ||
| imports needed to retain full functionality even without `std`. | ||
| Disabling the `alloc` feature removes the `BitVec` type, the `bitvec!` macro, | ||
| and all dynamic memory usage. The `BitSlice` type only loses its formatting | ||
| traits. | ||
| The configuration attributes in the source code are arrayed in order of | ||
| increasing functionality. That is, `#[cfg(not(feature = "alloc"))]` is first, | ||
| since it is only true when both `alloc` and `std` features are disabled, then | ||
| `#[cfg(all(feature = "alloc", not(feature = "std")))]` is second, since it is | ||
| true when `alloc` is enabled but `std` is not, and `#[cfg(feature = "std")]` is | ||
| last, since it is true when both `alloc` and `std` are present. | ||
| The `std` feature depends on `alloc`, so it is impossible to have `std` enabled | ||
| but `alloc` disabled. |
+7
-1
@@ -14,4 +14,5 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| [package] | ||
| edition = "2018" | ||
| name = "bitvec" | ||
| version = "0.6.0" | ||
| version = "0.8.0-e2018" | ||
| authors = ["myrrlyn <myrrlyn@outlook.com>"] | ||
@@ -25,1 +26,6 @@ description = "A crate for manipulating memory, bit by bit" | ||
| [dependencies] | ||
| [features] | ||
| alloc = [] | ||
| default = ["std"] | ||
| std = ["alloc"] |
+45
-0
@@ -5,2 +5,47 @@ # Changelog | ||
| ## 0.8.0 | ||
| ### Added | ||
| - `std` and `alloc` features, which can be disabled for use in `#![no_std]` | ||
| libraries. This was implemented by Robert Habermeier, `rphmeier@gmail.com`. | ||
| Note that the `BitSlice` tests and all the examples are disabled when the | ||
| `alloc` feature is not present. They will function normally when `alloc` is | ||
| present but `std` is not. | ||
| ### Changed | ||
| - Compute `Bits::WIDTH` as `size_of::<Self>() * 8` instead of `1 << Bits::BITS`. | ||
| ## 0.7.0 | ||
| ### Added | ||
| - `examples/readme.rs` tracks the contents of the example code in `README.md`. | ||
| It will continue to do so until the `external_doc` feature stabilizes so that | ||
| the contents of the README can be included in the module documentation of | ||
| `src/lib.rs`. | ||
| - Officially use the Rust community code of conduct. | ||
| - README sections describe why a user might want this library, and what makes it | ||
| different than `bit-vec`. | ||
| ### Changed | ||
| - Update minimum Rust version to `1.30.0`. | ||
| Internally, this permits use of `std` rather than `::std`. This compiler | ||
| edition does not change *intra-crate* macro usage. Clients at `1.30.0` and | ||
| above no longer need `#[macro_use]` above `extern crate bitvec;`, and are able | ||
| to import the `bitvec!` macro directly with `use bitvec::bitvec;` or | ||
| `use bitvec::*;`. | ||
| Implementation note: References to literals stabilized at *some* point between | ||
| `1.20.0` and `1.30.0`, so the static bool items used for indexing are no | ||
| longer needed. | ||
| - Include numeric arithmetic as well as set arithmetic in the README. | ||
| ## 0.6.0 | ||
@@ -7,0 +52,0 @@ |
+13
-1
@@ -25,7 +25,14 @@ /*! Sieve of Eratosthenes | ||
| #[cfg(feature = "alloc")] | ||
| extern crate bitvec; | ||
| use bitvec::*; | ||
| #[cfg(feature = "alloc")] | ||
| use bitvec::{ | ||
| BitVec, | ||
| BigEndian, | ||
| }; | ||
| #[cfg(feature = "alloc")] | ||
| use std::env; | ||
| #[cfg(feature = "alloc")] | ||
| fn main() { | ||
@@ -115,1 +122,6 @@ let max_prime: usize = env::args() | ||
| } | ||
| #[cfg(not(feature = "alloc"))] | ||
| fn main() { | ||
| println!("This example only runs when an allocator is present"); | ||
| } |
+41
-16
@@ -9,10 +9,28 @@ /*! Demonstrates construction and use of a big-endian, u8, `BitVec` | ||
| #[macro_use] | ||
| #[cfg(feature = "alloc")] | ||
| extern crate bitvec; | ||
| use bitvec::*; | ||
| #[cfg(feature = "alloc")] | ||
| use bitvec::{ | ||
| // `bitvec!` macro | ||
| bitvec, | ||
| // trait unifying the primitives (you shouldn’t explicitly need this) | ||
| Bits, | ||
| // primary type of the whole crate! this is where the magic happens | ||
| BitVec, | ||
| // element-traversal trait (you shouldn’t explicitly need this) | ||
| Endian, | ||
| // directionality type marker (the default for `BitVec`; you will rarely | ||
| // explicitly need this) | ||
| BigEndian, | ||
| // directionality type marker (you will explicitly need this if you want | ||
| // this ordering) | ||
| LittleEndian, | ||
| }; | ||
| #[cfg(feature = "alloc")] | ||
| use std::iter::repeat; | ||
| #[cfg(feature = "alloc")] | ||
| fn main() { | ||
| let bv = bitvec![ | ||
| let bv = bitvec![ // BigEndian, u8; // default type values | ||
| 0, 0, 0, 0, 0, 0, 0, 1, | ||
@@ -36,3 +54,4 @@ 0, 0, 0, 0, 0, 0, 1, 0, | ||
| ]; | ||
| println!("A BigEndian BitVec has the same layout in memory as it does semantically"); | ||
| println!("A BigEndian BitVec has the same layout in memory as it does \ | ||
| semantically"); | ||
| render(&bv); | ||
@@ -42,3 +61,4 @@ | ||
| let bv: BitVec<LittleEndian, u8> = bv.into_iter().collect(); | ||
| println!("A LittleEndian BitVec has the opposite layout in memory as it does semantically"); | ||
| println!("A LittleEndian BitVec has the opposite layout in memory as it \ | ||
| does semantically"); | ||
| render(&bv); | ||
@@ -78,15 +98,20 @@ | ||
| println!("End example"); | ||
| } | ||
| fn render<E: Endian, T: Bits>(bv: &BitVec<E, T>) { | ||
| println!("Memory information: {} {} {}", bv.elts(), bv.bits(), bv.len()); | ||
| println!("Print out the semantic contents"); | ||
| println!("{:#?}", bv); | ||
| println!("Print out the memory contents"); | ||
| println!("{:?}", bv.as_ref()); | ||
| println!("Show the bits in memory"); | ||
| for elt in bv.as_ref() { | ||
| println!("{:0w$b} ", elt, w=::std::mem::size_of::<T>() * 8); | ||
| fn render<E: Endian, T: Bits>(bv: &BitVec<E, T>) { | ||
| println!("Memory information: {} {} {}", bv.elts(), bv.bits(), bv.len()); | ||
| println!("Print out the semantic contents"); | ||
| println!("{:#?}", bv); | ||
| println!("Print out the memory contents"); | ||
| println!("{:?}", bv.as_ref()); | ||
| println!("Show the bits in memory"); | ||
| for elt in bv.as_ref() { | ||
| println!("{:0w$b} ", elt, w=std::mem::size_of::<T>() * 8); | ||
| } | ||
| println!(); | ||
| } | ||
| println!(); | ||
| } | ||
| #[cfg(not(feature = "alloc"))] | ||
| fn main() { | ||
| println!("This example only runs when an allocator is present"); | ||
| } |
+82
-16
@@ -25,4 +25,22 @@ # `BitVec` – Managing memory bit by bit | ||
| ## How Is This Different Than the `bit_vec` Crate | ||
| - It is more recently actively maintained (I may, in the future as of this | ||
| writing, let it lapse) | ||
| - It doesn’t have a hyphen in the name, so you don’t have to deal with the | ||
| hyphen/underscore dichotomy. | ||
| - My `BitVec` structure is exactly the size of a `Vec`; theirs is larger. | ||
| - I have a `BitSlice` borrowed view. | ||
| ## Why Would You Use This | ||
| - You need to directly control a bitstream’s representation in memory. | ||
| - You need to do unpleasant things with communications protocols. | ||
| - You need a list of `bool`s that doesn’t waste 7 bits for every bit used. | ||
| - You need to do set arithmetic, or numeric arithmetic, on those lists. | ||
| ## Usage | ||
| **Minimum Rust Version**: `1.30.0` | ||
| I wrote this crate because I was unhappy with the other bit-vector crates | ||
@@ -42,3 +60,3 @@ available. I specifically need to manage raw memory in bit-level precision, and | ||
| [dependencies] | ||
| bitvec = "0.6" | ||
| bitvec = "0.8" | ||
| ``` | ||
@@ -49,3 +67,2 @@ | ||
| ```rust,no-run | ||
| #[macro_use] | ||
| extern crate bitvec; | ||
@@ -56,5 +73,8 @@ | ||
| This gives you access to the `bitvec!` macro for building `BitVec` types | ||
| similarly to the `vec!` macro, and imports the following symbols: | ||
| This imports the following symbols: | ||
| - `bitvec!` – a macro similar to `vec!`, which allows the creation of `BitVec`s | ||
| of any desired endianness, storage type, and contents. The documentation page | ||
| has a detailed explanation of its syntax. | ||
| - `BitSlice<E: Endian, T: Bits>` – the actual bit-slice reference type It is | ||
@@ -117,6 +137,45 @@ generic over a cursor type (`E`) and storage type (`T`). Note that `BitSlice` | ||
| ### `no_std` | ||
| This crate can be used in `#![no_std]` libraries, by disabling the default | ||
| feature set. In your `Cargo.toml`, write: | ||
| ```toml | ||
| [dependencies] | ||
| bitvec = { version = "0.8", default-features = false } | ||
| ``` | ||
| or | ||
| ```toml | ||
| [dependencies.bitvec] | ||
| version = "0.8" | ||
| default-features = false | ||
| ``` | ||
| This turns off the standard library imports *and* all usage of dynamic memory | ||
| allocation. Without an allocator, the `bitvec!` macro and the `BitVec` type are | ||
| both disable and removed from the library, leaving only the `BitSlice` type. | ||
| To use `bitvec` in a `#![no_std]` environment that *does* have an allocator, | ||
| re-enable the `alloc` feature, like so: | ||
| ```toml | ||
| [dependencies.bitvec] | ||
| version = "0.8" | ||
| default-features = false | ||
| features = ["alloc"] | ||
| ``` | ||
| The `alloc` feature restores `bitvec!` and `BitVec`, as well as the `BitSlice` | ||
| interoperability with `BitVec`. The only difference between `alloc` and `std` is | ||
| the presence of the standard library façade and runtime support. | ||
| The `std` feature turns on `alloc`, so using this crate without any feature | ||
| flags *or* by explicitly enabling the `std` feature will enable full | ||
| functionality. | ||
| ## Example | ||
| ```rust | ||
| #[macro_use] | ||
| extern crate bitvec; | ||
@@ -131,5 +190,3 @@ | ||
| bv.reserve(8); | ||
| for bit in repeat(false).take(4).chain(repeat(true).take(4)) { | ||
| bv.push(bit); | ||
| } | ||
| bv.extend(repeat(false).take(4).chain(repeat(true).take(4))); | ||
@@ -142,14 +199,21 @@ // Memory access | ||
| // Arithmetic operations | ||
| // Set operations | ||
| bv &= repeat(true); | ||
| bv = bv | repeat(false); | ||
| bv ^= repeat(false); | ||
| bv ^= repeat(true); | ||
| bv = !bv; | ||
| // Arithmetic operations | ||
| let one = bitvec![1]; | ||
| bv += one.clone(); | ||
| assert_eq!(bv.as_ref(), &[0b0101_0001, 0b0000_0000]); | ||
| bv -= one.clone(); | ||
| assert_eq!(bv.as_ref(), &[0b0101_0000, 0b1111_0000]); | ||
| // Borrowing iteration | ||
| let mut iter = bv.iter(); | ||
| // index 0 | ||
| if let Some(false) = iter.next() {} else { panic!() }; | ||
| assert_eq!(iter.next().unwrap(), false); | ||
| // index 11 | ||
| if let Some(true) = iter.next_back() {} else { panic!() }; | ||
| assert_eq!(iter.next_back().unwrap(), true); | ||
| assert_eq!(iter.len(), 10); | ||
@@ -175,7 +239,9 @@ } | ||
| - `#![no_std]` support that uses core libraries for allocation, and | ||
| `#![no_core]` support that strips the vector type entirely and only provides | ||
| Contributions of items in this list are *absolutely* welcome! Contributions of | ||
| other features are also welcome, but I’ll have to be sold on them. | ||
| - `#![no_core]` support that strips the vector type entirely and only provides | ||
| the slice type. | ||
| - A `Box<BitSlice>` type that corresponds to `Box<[T]>` between `&[T]` and | ||
| `Vec<T>`. | ||
| - Creation of specialized pointers `Box<BitSlice>`, `Rc<BitSlice>`, and | ||
| `Arc<BitSlice>`. |
+6
-5
@@ -8,3 +8,3 @@ /*! Bit Management | ||
| use std::{ | ||
| use core::{ | ||
| cmp::Eq, | ||
@@ -20,2 +20,3 @@ convert::From, | ||
| }, | ||
| mem::size_of, | ||
| ops::{ | ||
@@ -71,3 +72,3 @@ Not, | ||
| /// The width in bits of this type. | ||
| const WIDTH: u8 = 1 << Self::BITS; // size_of::<Self>(); | ||
| const WIDTH: u8 = size_of::<Self>() as u8 * 8; | ||
@@ -79,3 +80,3 @@ /// The number of bits required to *index* the type. This is always | ||
| /// that becomes a valid constexpr. | ||
| const BITS: u8; // = size_of::<Self>().trailing_zeroes(); | ||
| const BITS: u8; // = size_of::<Self>().trailing_zeros(); | ||
@@ -87,3 +88,3 @@ /// The bitmask to turn an arbitrary usize into the bit index. Bit indices | ||
| /// The maximum number of this type that can be held in a `BitVec`. | ||
| const MAX_ELT: usize = ::std::usize::MAX >> Self::BITS; | ||
| const MAX_ELT: usize = core::usize::MAX >> Self::BITS; | ||
@@ -122,3 +123,3 @@ /// Set a specific bit in an element to a given value. | ||
| fn join(elt: usize, bit: u8) -> usize { | ||
| assert!(elt <= ::std::usize::MAX >> Self::BITS, "Element count out of range!"); | ||
| assert!(elt <= core::usize::MAX >> Self::BITS, "Element count out of range!"); | ||
| assert!(bit <= Self::MASK, "Bit count out of range!"); | ||
@@ -125,0 +126,0 @@ (elt << Self::BITS) | bit as usize |
+4
-4
@@ -264,9 +264,9 @@ /*! Endianness Markers | ||
| let start = 20; | ||
| let (elt, bit) = LittleEndian::jump::<u32>(start, ::std::isize::MAX); | ||
| let (elt, bit) = LittleEndian::jump::<u32>(start, core::isize::MAX); | ||
| assert_eq!(elt as usize, ::std::isize::MIN as usize >> u32::BITS); | ||
| assert_eq!(elt as usize, core::isize::MIN as usize >> u32::BITS); | ||
| assert_eq!(bit, start - 1); | ||
| let (elt, bit) = BigEndian::jump::<u32>(start, ::std::isize::MAX); | ||
| assert_eq!(elt as usize, ::std::isize::MIN as usize >> u32::BITS); | ||
| let (elt, bit) = BigEndian::jump::<u32>(start, core::isize::MAX); | ||
| assert_eq!(elt as usize, core::isize::MIN as usize >> u32::BITS); | ||
| assert_eq!(bit, BigEndian::curr::<u32>(start) - 1); | ||
@@ -273,0 +273,0 @@ } |
+20
-12
@@ -36,2 +36,11 @@ /*! `BitVec` – `Vec<bool>` in overdrive. | ||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
| #![cfg_attr(all(feature = "alloc", not(feature = "std")), feature(alloc))] | ||
| #[cfg(all(feature = "alloc", not(feature = "std")))] | ||
| extern crate alloc; | ||
| #[cfg(feature = "std")] | ||
| extern crate core; | ||
| #[macro_use] | ||
@@ -43,18 +52,17 @@ mod macros; | ||
| mod slice; | ||
| mod vec; | ||
| pub use { | ||
| pub use crate::{ | ||
| bits::Bits, | ||
| endian::*, | ||
| macros::*, | ||
| endian::{ | ||
| Endian, | ||
| BigEndian, | ||
| LittleEndian, | ||
| }, | ||
| slice::BitSlice, | ||
| vec::BitVec, | ||
| }; | ||
| // The `Index` trait returns references to bools, and it is impossible to make | ||
| // an address for a bit in the middle of a byte. Therefore, `Index::index` | ||
| // references these static values depending on the value of the bit. | ||
| // | ||
| // This is *such* a hack, but, That’s Rust For Ya. | ||
| static TRUE: bool = true; | ||
| static FALSE: bool = false; | ||
| #[cfg(feature = "alloc")] | ||
| mod vec; | ||
| #[cfg(feature = "alloc")] | ||
| pub use crate::vec::BitVec; |
+48
-46
@@ -32,44 +32,45 @@ /** Construct a `BitVec` out of a literal array in source code, like `vec!`. | ||
| **/ | ||
| #[cfg(feature = "alloc")] | ||
| #[macro_export] | ||
| macro_rules! bitvec { | ||
| // bitvec![endian, type ; 0, 1, …] | ||
| ( $endian:ident , $primitive:ty ; $( $elt:expr ),* ) => { | ||
| bitvec![ __bv_impl__ $endian , $primitive ; $( $elt ),* ] | ||
| ( $endian:ident , $bits:ty ; $( $element:expr ),* ) => { | ||
| bitvec![ __bv_impl__ $endian , $bits ; $( $element ),* ] | ||
| }; | ||
| // bitvec![endian, type ; 0, 1, …, ] | ||
| ( $endian:ident , $primitive:ty ; $( $elt:expr , )* ) => { | ||
| bitvec![ __bv_impl__ $endian , $primitive ; $( $elt ),* ] | ||
| ( $endian:ident , $bits:ty ; $( $element:expr , )* ) => { | ||
| bitvec![ __bv_impl__ $endian , $bits ; $( $element ),* ] | ||
| }; | ||
| // bitvec![endian ; 0, 1, …] | ||
| ( $endian:ident ; $( $elt:expr ),* ) => { | ||
| bitvec![ __bv_impl__ $endian , u8 ; $( $elt ),* ] | ||
| ( $endian:ident ; $( $element:expr ),* ) => { | ||
| bitvec![ __bv_impl__ $endian , u8 ; $( $element ),* ] | ||
| }; | ||
| // bitvec![endian ; 0, 1, …, ] | ||
| ( $endian:ident ; $( $elt:expr , )* ) => { | ||
| bitvec![ __bv_impl__ $endian , u8 ; $( $elt ),* ] | ||
| ( $endian:ident ; $( $element:expr , )* ) => { | ||
| bitvec![ __bv_impl__ $endian , u8 ; $( $element ),* ] | ||
| }; | ||
| // bitvec![0, 1, …] | ||
| ( $( $elt:expr ),* ) => { | ||
| bitvec![ __bv_impl__ BigEndian , u8 ; $($elt),* ] | ||
| ( $( $element:expr ),* ) => { | ||
| bitvec![ __bv_impl__ BigEndian , u8 ; $($element),* ] | ||
| }; | ||
| // bitvec![0, 1, …, ] | ||
| ( $( $elt:expr , )* ) => { | ||
| bitvec![ __bv_impl__ BigEndian , u8 ; $($elt),* ] | ||
| ( $( $element:expr , )* ) => { | ||
| bitvec![ __bv_impl__ BigEndian , u8 ; $($element),* ] | ||
| }; | ||
| // bitvec![endian, type; bit; rep] | ||
| ( $endian:ident , $primitive:ty ; $elt:expr ; $rep:expr ) => { | ||
| bitvec![ __bv_impl__ $endian , $primitive ; $elt; $rep ] | ||
| ( $endian:ident , $bits:ty ; $element:expr ; $rep:expr ) => { | ||
| bitvec![ __bv_impl__ $endian , $bits ; $element; $rep ] | ||
| }; | ||
| // bitvec![endian; bit; rep] | ||
| ( $endian:ident ; $elt:expr ; $rep:expr ) => { | ||
| bitvec![ __bv_impl__ $endian , u8 ; $elt; $rep ] | ||
| ( $endian:ident ; $element:expr ; $rep:expr ) => { | ||
| bitvec![ __bv_impl__ $endian , u8 ; $element; $rep ] | ||
| }; | ||
| // bitvec![bit; rep] | ||
| ( $elt:expr ; $rep:expr ) => { | ||
| bitvec![ __bv_impl__ BigEndian , u8 ; $elt; $rep ] | ||
| ( $element:expr ; $rep:expr ) => { | ||
| bitvec![ __bv_impl__ BigEndian , u8 ; $element; $rep ] | ||
| }; | ||
@@ -85,13 +86,13 @@ | ||
| ( __bv_impl__ $end:ident , $prim:ty ; $( $elt:expr ),* ) => {{ | ||
| ( __bv_impl__ $endian:ident , $bits:ty ; $( $element:expr ),* ) => {{ | ||
| let init: &[bool] = &[ | ||
| $( $elt as u8 > 0 ),* | ||
| $( $element as u8 > 0 ),* | ||
| ]; | ||
| $crate :: BitVec ::< $crate :: $end , $prim >:: from(init) | ||
| $crate :: BitVec ::< $endian , $bits >:: from(init) | ||
| }}; | ||
| ( __bv_impl__ $end:ident , $prim:ty ; $elt:expr; $rep:expr ) => {{ | ||
| ::std::iter::repeat( $elt as u8 > 0 ) | ||
| ( __bv_impl__ $endian:ident , $bits:ty ; $element:expr; $rep:expr ) => {{ | ||
| core::iter::repeat( $element as u8 > 0 ) | ||
| .take( $rep ) | ||
| .collect ::< $crate :: BitVec < $crate :: $end , $prim > > () | ||
| .collect ::< $crate :: BitVec < $endian , $bits > > () | ||
| }}; | ||
@@ -104,7 +105,7 @@ } | ||
| #[doc(hidden)] | ||
| impl<E: $crate::Endian, T: $crate::Bits> ::std::ops::ShlAssign< $t > | ||
| for $crate::BitSlice<E, T> | ||
| impl<E: $crate :: Endian, T: $crate :: Bits> core::ops::ShlAssign< $t > | ||
| for crate::BitSlice<E, T> | ||
| { | ||
| fn shl_assign(&mut self, shamt: $t ) { | ||
| ::std::ops::ShlAssign::<usize>::shl_assign(self, shamt as usize); | ||
| core::ops::ShlAssign::<usize>::shl_assign(self, shamt as usize); | ||
| } | ||
@@ -114,7 +115,7 @@ } | ||
| #[doc(hidden)] | ||
| impl<E: $crate::Endian, T: $crate::Bits> ::std::ops::ShrAssign< $t > | ||
| for $crate::BitSlice<E, T> | ||
| impl<E: $crate :: Endian, T: $crate :: Bits> core::ops::ShrAssign< $t > | ||
| for crate::BitSlice<E, T> | ||
| { | ||
| fn shr_assign(&mut self, shamt: $t ) { | ||
| ::std::ops::ShrAssign::<usize>::shr_assign(self, shamt as usize); | ||
| core::ops::ShrAssign::<usize>::shr_assign(self, shamt as usize); | ||
| } | ||
@@ -125,2 +126,3 @@ } | ||
| #[cfg(feature = "alloc")] | ||
| #[doc(hidden)] | ||
@@ -130,9 +132,9 @@ macro_rules! __bitvec_shift { | ||
| #[doc(hidden)] | ||
| impl<E: $crate::Endian, T: $crate::Bits> ::std::ops::Shl< $t > | ||
| for $crate::BitVec<E, T> | ||
| impl<E: $crate :: Endian, T: $crate :: Bits> core::ops::Shl< $t > | ||
| for $crate :: BitVec<E, T> | ||
| { | ||
| type Output = <Self as ::std::ops::Shl<usize>>::Output; | ||
| type Output = <Self as core::ops::Shl<usize>>::Output; | ||
| fn shl(self, shamt: $t ) -> Self::Output { | ||
| ::std::ops::Shl::<usize>::shl(self, shamt as usize) | ||
| core::ops::Shl::<usize>::shl(self, shamt as usize) | ||
| } | ||
@@ -142,7 +144,7 @@ } | ||
| #[doc(hidden)] | ||
| impl<E: $crate::Endian, T: $crate::Bits> ::std::ops::ShlAssign< $t > | ||
| for $crate::BitVec<E, T> | ||
| impl<E: $crate :: Endian, T: $crate :: Bits> core::ops::ShlAssign< $t > | ||
| for $crate :: BitVec<E, T> | ||
| { | ||
| fn shl_assign(&mut self, shamt: $t ) { | ||
| ::std::ops::ShlAssign::<usize>::shl_assign(self, shamt as usize) | ||
| core::ops::ShlAssign::<usize>::shl_assign(self, shamt as usize) | ||
| } | ||
@@ -152,9 +154,9 @@ } | ||
| #[doc(hidden)] | ||
| impl<E: $crate::Endian, T: $crate::Bits> ::std::ops::Shr< $t > | ||
| for $crate::BitVec<E, T> | ||
| impl<E: $crate :: Endian, T: $crate :: Bits> core::ops::Shr< $t > | ||
| for $crate :: BitVec<E, T> | ||
| { | ||
| type Output = <Self as ::std::ops::Shr<usize>>::Output; | ||
| type Output = <Self as core::ops::Shr<usize>>::Output; | ||
| fn shr(self, shamt: $t ) -> Self::Output { | ||
| ::std::ops::Shr::<usize>::shr(self, shamt as usize) | ||
| core::ops::Shr::<usize>::shr(self, shamt as usize) | ||
| } | ||
@@ -164,7 +166,7 @@ } | ||
| #[doc(hidden)] | ||
| impl<E: $crate::Endian, T: $crate::Bits> ::std::ops::ShrAssign< $t > | ||
| for $crate::BitVec<E, T> | ||
| impl<E: $crate :: Endian, T: $crate :: Bits> core::ops::ShrAssign< $t > | ||
| for $crate :: BitVec<E, T> | ||
| { | ||
| fn shr_assign(&mut self, shamt: $t ) { | ||
| ::std::ops::ShrAssign::<usize>::shr_assign(self, shamt as usize) | ||
| core::ops::ShrAssign::<usize>::shr_assign(self, shamt as usize) | ||
| } | ||
@@ -175,6 +177,6 @@ } | ||
| #[cfg(test)] | ||
| #[cfg(all(test, feature = "alloc"))] | ||
| mod tests { | ||
| #[allow(unused_imports)] | ||
| use { | ||
| use crate::{ | ||
| BigEndian, | ||
@@ -181,0 +183,0 @@ LittleEndian, |
+192
-67
@@ -38,12 +38,3 @@ /*! `BitSlice` Wide Reference | ||
| use { | ||
| Bits, | ||
| Endian, | ||
| BigEndian, | ||
| BitVec, | ||
| TRUE, | ||
| FALSE, | ||
| }; | ||
| use std::{ | ||
| borrow::ToOwned, | ||
| use core::{ | ||
| cmp::{ | ||
@@ -61,8 +52,2 @@ Eq, | ||
| }, | ||
| fmt::{ | ||
| self, | ||
| Debug, | ||
| Display, | ||
| Formatter, | ||
| }, | ||
| hash::{ | ||
@@ -95,2 +80,16 @@ Hash, | ||
| #[cfg(feature = "alloc")] | ||
| use core::fmt::{ | ||
| self, | ||
| Debug, | ||
| Display, | ||
| Formatter, | ||
| }; | ||
| #[cfg(all(feature = "alloc", not(feature = "std")))] | ||
| use alloc::borrow::ToOwned; | ||
| #[cfg(feature = "std")] | ||
| use std::borrow::ToOwned; | ||
| /** A compact slice of bits, whose cursor and storage type can be customized. | ||
@@ -124,4 +123,4 @@ | ||
| #[cfg_attr(nightly, repr(transparent))] | ||
| pub struct BitSlice<E = BigEndian, T = u8> | ||
| where E: Endian, T: Bits { | ||
| pub struct BitSlice<E = crate::BigEndian, T = u8> | ||
| where E: crate::Endian, T: crate::Bits { | ||
| _endian: PhantomData<E>, | ||
@@ -132,3 +131,3 @@ inner: [T], | ||
| impl<E, T> BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| where E: crate::Endian, T: crate::Bits { | ||
| /// Gets the bit value at the given position. | ||
@@ -142,2 +141,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -147,2 +147,3 @@ /// let bv = bitvec![0, 0, 1, 0, 0]; | ||
| /// assert!(bits.get(2)); | ||
| /// # } | ||
| /// ``` | ||
@@ -163,2 +164,3 @@ pub fn get(&self, index: usize) -> bool { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -169,2 +171,3 @@ /// let mut bv = bitvec![0; 5]; | ||
| /// assert!(bits.get(2)); | ||
| /// # } | ||
| /// ``` | ||
@@ -191,2 +194,3 @@ pub fn set(&mut self, index: usize, value: bool) { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -202,2 +206,3 @@ /// let all = bitvec![1; 10]; | ||
| /// assert!(!none.all()); | ||
| /// # } | ||
| /// ``` | ||
@@ -222,3 +227,3 @@ pub fn all(&self) -> bool { | ||
| } | ||
| return true; | ||
| true | ||
| } | ||
@@ -240,2 +245,3 @@ | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -251,2 +257,3 @@ /// let all = bitvec![1; 10]; | ||
| /// assert!(!none.any()); | ||
| /// # } | ||
| /// ``` | ||
@@ -271,3 +278,3 @@ pub fn any(&self) -> bool { | ||
| } | ||
| return false; | ||
| false | ||
| } | ||
@@ -289,2 +296,3 @@ | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -300,2 +308,3 @@ /// let all = bitvec![1; 10]; | ||
| /// assert!(none.not_all()); | ||
| /// # } | ||
| /// ``` | ||
@@ -320,2 +329,3 @@ pub fn not_all(&self) -> bool { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -331,2 +341,3 @@ /// let all = bitvec![1; 10]; | ||
| /// assert!(none.not_any()); | ||
| /// # } | ||
| /// ``` | ||
@@ -354,2 +365,3 @@ pub fn not_any(&self) -> bool { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -363,2 +375,3 @@ /// let all = bitvec![1; 2]; | ||
| /// assert!(!none.some()); | ||
| /// # } | ||
| /// ``` | ||
@@ -374,5 +387,7 @@ pub fn some(&self) -> bool { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
| /// let bv = bitvec![1, 0, 1, 0, 1]; | ||
| /// assert_eq!(bv.count_ones(), 3); | ||
| /// # } | ||
| /// ``` | ||
@@ -388,5 +403,7 @@ pub fn count_ones(&self) -> usize { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
| /// let bv = bitvec![0, 1, 0, 1, 0]; | ||
| /// assert_eq!(bv.count_zeros(), 3); | ||
| /// # } | ||
| /// ``` | ||
@@ -402,2 +419,3 @@ pub fn count_zeros(&self) -> usize { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -407,2 +425,3 @@ /// let bv = bitvec![1; 10]; | ||
| /// assert_eq!(bits.len(), 10); | ||
| /// # } | ||
| /// ``` | ||
@@ -422,2 +441,3 @@ pub fn len(&self) -> usize { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -427,5 +447,7 @@ /// let bv = bitvec![1; 10]; | ||
| /// assert_eq!(bits.elts(), 1); | ||
| /// # } | ||
| /// ``` | ||
| /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -435,2 +457,3 @@ /// let bv = bitvec![1; 16]; | ||
| /// assert_eq!(bits.elts(), 2); | ||
| /// # } | ||
| /// ``` | ||
@@ -450,2 +473,3 @@ pub fn elts(&self) -> usize { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -455,5 +479,7 @@ /// let bv = bitvec![1; 10]; | ||
| /// assert_eq!(bits.bits(), 2); | ||
| /// # } | ||
| /// ``` | ||
| /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -463,2 +489,3 @@ /// let bv = bitvec![1; 16]; | ||
| /// assert_eq!(bits.bits(), 0); | ||
| /// # } | ||
| /// ``` | ||
@@ -474,2 +501,3 @@ pub fn bits(&self) -> u8 { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -479,5 +507,7 @@ /// let bv = bitvec![]; | ||
| /// assert!(bits.is_empty()); | ||
| /// # } | ||
| /// ``` | ||
| /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -487,2 +517,3 @@ /// let bv = bitvec![0; 5]; | ||
| /// assert!(!bits.is_empty()); | ||
| /// # } | ||
| /// ``` | ||
@@ -498,3 +529,3 @@ pub fn is_empty(&self) -> bool { | ||
| /// iterator does. | ||
| pub fn iter<'a>(&'a self) -> Iter<'a, E, T> { | ||
| pub fn iter(&self) -> Iter<E, T> { | ||
| self.into_iter() | ||
@@ -513,2 +544,3 @@ } | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -526,4 +558,5 @@ /// let mut bv = bitvec![1; 8]; | ||
| /// assert_eq!(&[0b01010101], bref.as_ref()); | ||
| /// # } | ||
| /// ``` | ||
| pub fn for_each<'a, F>(&'a mut self, op: F) | ||
| pub fn for_each<F>(&mut self, op: F) | ||
| where F: Fn(usize, bool) -> bool { | ||
@@ -552,2 +585,3 @@ for idx in 0 .. self.len() { | ||
| /// ```rust,ignore | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -558,3 +592,7 @@ /// let bv = bitvec![1; 10]; | ||
| /// assert_eq!(bits.raw_len(), 2); | ||
| /// # } | ||
| /// ``` | ||
| /// | ||
| /// This test is never compiled because the functions it calls are not | ||
| /// accessible to the test crate. | ||
| pub(crate) fn raw_len(&self) -> usize { | ||
@@ -565,2 +603,3 @@ self.elts() + if self.bits() > 0 { 1 } else { 0 } | ||
| /// Prints a type header into the Formatter. | ||
| #[cfg(feature = "alloc")] | ||
| pub(crate) fn fmt_header(&self, fmt: &mut Formatter) -> fmt::Result { | ||
@@ -574,2 +613,3 @@ write!(fmt, "BitSlice<{}, {}>", E::TY, T::TY) | ||
| /// `Display` does not). | ||
| #[cfg(feature = "alloc")] | ||
| pub(crate) fn fmt_body(&self, fmt: &mut Formatter, debug: bool) -> fmt::Result { | ||
@@ -580,4 +620,4 @@ let (elts, bits) = T::split(self.len()); | ||
| let alt = fmt.alternate(); | ||
| for idx in 0 .. elts { | ||
| Self::fmt_element(fmt, &buf[idx])?; | ||
| for (idx, elt) in buf.iter().take(elts).enumerate() { | ||
| Self::fmt_element(fmt, elt)?; | ||
| if idx < len - 1 { | ||
@@ -603,2 +643,3 @@ match (alt, debug) { | ||
| /// Formats a whole storage element of the data slice. | ||
| #[cfg(feature = "alloc")] | ||
| pub(crate) fn fmt_element(fmt: &mut Formatter, elt: &T) -> fmt::Result { | ||
@@ -609,4 +650,9 @@ Self::fmt_bits(fmt, elt, T::WIDTH) | ||
| /// Formats a partial element of the data slice. | ||
| #[cfg(feature = "alloc")] | ||
| pub(crate) fn fmt_bits(fmt: &mut Formatter, elt: &T, bits: u8) -> fmt::Result { | ||
| use std::fmt::Write; | ||
| use core::fmt::Write; | ||
| #[cfg(not(feature = "std"))] | ||
| use alloc::string::String; | ||
| let mut out = String::with_capacity(bits as usize); | ||
@@ -622,5 +668,6 @@ for bit in 0 .. bits { | ||
| /// Creates a new `BitVec` out of a `BitSlice`. | ||
| #[cfg(feature = "alloc")] | ||
| impl<E, T> ToOwned for BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| type Owned = BitVec<E, T>; | ||
| where E: crate::Endian, T: crate::Bits { | ||
| type Owned = crate::BitVec<E, T>; | ||
@@ -632,2 +679,3 @@ /// Clones a borrowed `BitSlice` into an owned `BitVec`. | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -638,2 +686,3 @@ /// let src = bitvec![0; 5]; | ||
| /// assert_eq!(src, dst); | ||
| /// # } | ||
| /// ``` | ||
@@ -654,6 +703,6 @@ fn to_owned(&self) -> Self::Owned { | ||
| impl<E, T> Eq for BitSlice<E, T> | ||
| where E: Endian, T: Bits {} | ||
| where E: crate::Endian, T: crate::Bits {} | ||
| impl<E, T> Ord for BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| where E: crate::Endian, T: crate::Bits { | ||
| fn cmp(&self, rhs: &Self) -> Ordering { | ||
@@ -674,3 +723,3 @@ match self.partial_cmp(rhs) { | ||
| impl<A, B, C, D> PartialEq<BitSlice<C, D>> for BitSlice<A, B> | ||
| where A: Endian, B: Bits, C: Endian, D: Bits { | ||
| where A: crate::Endian, B: crate::Bits, C: crate::Endian, D: crate::Bits { | ||
| /// Performs a comparison by `==`. | ||
@@ -681,2 +730,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -689,2 +739,3 @@ /// let l: BitVec<LittleEndian, u16> = bitvec![LittleEndian, u16; 0, 1, 0, 1]; | ||
| /// assert!(ls == rs); | ||
| /// # } | ||
| /// ``` | ||
@@ -709,3 +760,3 @@ fn eq(&self, rhs: &BitSlice<C, D>) -> bool { | ||
| impl<A, B, C, D> PartialOrd<BitSlice<C, D>> for BitSlice<A, B> | ||
| where A: Endian, B: Bits, C: Endian, D: Bits { | ||
| where A: crate::Endian, B: crate::Bits, C: crate::Endian, D: crate::Bits { | ||
| /// Performs a comparison by `<` or `>`. | ||
@@ -716,2 +767,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -726,2 +778,3 @@ /// let a = bitvec![0, 1, 0, 0]; | ||
| /// assert!(bref < cref); | ||
| /// # } | ||
| /// ``` | ||
@@ -743,3 +796,3 @@ fn partial_cmp(&self, rhs: &BitSlice<C, D>) -> Option<Ordering> { | ||
| impl<E, T> AsMut<[T]> for BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| where E: crate::Endian, T: crate::Bits { | ||
| /// Accesses the underlying store. | ||
@@ -750,2 +803,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -757,2 +811,3 @@ /// let mut bv: BitVec = bitvec![0, 0, 0, 0, 0, 0, 0, 0, 1]; | ||
| /// assert_eq!(&[2, 130], bv.as_ref()); | ||
| /// # } | ||
| /// ``` | ||
@@ -768,3 +823,3 @@ fn as_mut(&mut self) -> &mut [T] { | ||
| impl<E, T> AsRef<[T]> for BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| where E: crate::Endian, T: crate::Bits { | ||
| /// Accesses the underlying store. | ||
@@ -775,2 +830,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -780,2 +836,3 @@ /// let bv = bitvec![0, 0, 0, 0, 0, 0, 0, 0, 1]; | ||
| /// assert_eq!(&[0, 0b1000_0000], bref.as_ref()); | ||
| /// # } | ||
| /// ``` | ||
@@ -791,3 +848,3 @@ fn as_ref(&self) -> &[T] { | ||
| impl<'a, E, T> From<&'a [T]> for &'a BitSlice<E, T> | ||
| where E: Endian, T: 'a + Bits { | ||
| where E: crate::Endian, T: 'a + crate::Bits { | ||
| /// Wraps an `&[T: Bits]` in an `&BitSlice<E: Endian, T>`. The endianness | ||
@@ -799,2 +856,3 @@ /// must be specified by the call site. The element type cannot be changed. | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -811,2 +869,3 @@ /// let src = vec![1u8, 2, 3]; | ||
| /// assert!(bits.get(23)); | ||
| /// # } | ||
| /// ``` | ||
@@ -817,2 +876,5 @@ fn from(src: &'a [T]) -> Self { | ||
| unsafe { | ||
| // This is the correct construction of an `&BitSlice` wide pointer | ||
| // from a standard slice wide pointer. | ||
| #[allow(clippy::transmute_ptr_to_ptr)] | ||
| mem::transmute( | ||
@@ -829,3 +891,3 @@ slice::from_raw_parts(ptr, len << T::BITS) | ||
| impl<'a, E, T> From<&'a mut [T]> for &'a mut BitSlice<E, T> | ||
| where E: Endian, T: 'a + Bits { | ||
| where E: crate::Endian, T: 'a + crate::Bits { | ||
| /// Wraps an `&mut [T: Bits]` in an `&mut BitSlice<E: Endian, T>`. The | ||
@@ -838,2 +900,3 @@ /// endianness must be specified by the call site. The element type cannot | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -847,2 +910,3 @@ /// let mut src = vec![1u8, 2, 3]; | ||
| /// assert!(!bits.get(0)); | ||
| /// # } | ||
| /// ``` | ||
@@ -853,2 +917,5 @@ fn from(src: &'a mut [T]) -> Self { | ||
| unsafe { | ||
| // This is the correct construction of an `&BitSlice` wide pointer | ||
| // from a standard slice wide pointer. | ||
| #[allow(clippy::transmute_ptr_to_ptr)] | ||
| mem::transmute( | ||
@@ -871,4 +938,5 @@ slice::from_raw_parts_mut(ptr, len << T::BITS) | ||
| /// than having all elements on the same line. | ||
| #[cfg(feature = "alloc")] | ||
| impl<E, T> Debug for BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| where E: crate::Endian, T: crate::Bits { | ||
| /// Renders the `BitSlice` type header and contents for debug. | ||
@@ -879,2 +947,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -890,2 +959,3 @@ /// let bits: &BitSlice<LittleEndian, u16> = &bitvec![ | ||
| /// ); | ||
| /// # } | ||
| /// ``` | ||
@@ -913,4 +983,5 @@ fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { | ||
| /// raw elements and print that slice instead. | ||
| #[cfg(feature = "alloc")] | ||
| impl<E, T> Display for BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| where E: crate::Endian, T: crate::Bits { | ||
| /// Renders the `BitSlice` contents for display. | ||
@@ -921,5 +992,7 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
| /// let bits: &BitSlice = &bitvec![0, 1, 0, 0, 1, 0, 1, 1, 0, 1]; | ||
| /// assert_eq!("01001011 01", &format!("{}", bits)); | ||
| /// # } | ||
| /// ``` | ||
@@ -933,3 +1006,3 @@ fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { | ||
| impl<E, T> Hash for BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| where E: crate::Endian, T: crate::Bits { | ||
| /// Writes each bit of the `BitSlice`, as a full `bool`, into the hasher. | ||
@@ -950,3 +1023,3 @@ fn hash<H>(&self, hasher: &mut H) | ||
| impl<'a, E, T> IntoIterator for &'a BitSlice<E, T> | ||
| where E: Endian, T: 'a + Bits { | ||
| where E: crate::Endian, T: 'a + crate::Bits { | ||
| type Item = bool; | ||
@@ -960,2 +1033,3 @@ type IntoIter = Iter<'a, E, T>; | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -969,2 +1043,3 @@ /// let bv = bitvec![1, 0, 1, 0, 1, 1, 0, 0]; | ||
| /// assert_eq!(count, 4); | ||
| /// # } | ||
| /// ``` | ||
@@ -992,3 +1067,3 @@ fn into_iter(self) -> Self::IntoIter { | ||
| impl<'a, E, T> AddAssign<&'a BitSlice<E, T>> for BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| where E: crate::Endian, T: crate::Bits { | ||
| /// Performs unsigned wrapping addition in place. | ||
@@ -1001,2 +1076,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1015,5 +1091,16 @@ /// let nums: [BitVec; 3] = [ | ||
| /// assert_eq!(numr, &nums[2] as &BitSlice); | ||
| /// # } | ||
| /// ``` | ||
| // Clippy thinks single-letter names are risky. This is generall an apt | ||
| // assumption, but here, the letters `a`, `b`, `c`, `y`, and `z` have | ||
| // fairly standardized, well-known meanings in digital arithmetic. | ||
| // For clarity, however: | ||
| // - a : The primary addend bit | ||
| // - b : The secondary addend bit | ||
| // - c : The carry-in bit | ||
| // - y : The sum bit | ||
| // - z : The carry-out bit | ||
| #[allow(clippy::many_single_char_names)] | ||
| fn add_assign(&mut self, addend: &'a BitSlice<E, T>) { | ||
| use std::iter::repeat; | ||
| use core::iter::repeat; | ||
| // zero-extend the addend if it’s shorter than self | ||
@@ -1040,3 +1127,3 @@ let mut addend_iter = addend.into_iter().rev().chain(repeat(false)); | ||
| impl<E, T, I> BitAndAssign<I> for BitSlice<E, T> | ||
| where E: Endian, T: Bits, I: IntoIterator<Item=bool> { | ||
| where E: crate::Endian, T: crate::Bits, I: IntoIterator<Item=bool> { | ||
| /// `AND`s a bitstream into a slice. | ||
@@ -1047,2 +1134,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1053,5 +1141,6 @@ /// let lhs: &mut BitSlice = &mut bitvec![0, 1, 0, 1, 0, 1]; | ||
| /// assert_eq!("000100", &format!("{}", lhs)); | ||
| /// # } | ||
| /// ``` | ||
| fn bitand_assign(&mut self, rhs: I) { | ||
| use std::iter::repeat; | ||
| use core::iter::repeat; | ||
| for (idx, other) in (0 .. self.len()).zip(rhs.into_iter().chain(repeat(false))) { | ||
@@ -1068,3 +1157,3 @@ let val = self.get(idx) & other; | ||
| impl<E, T, I> BitOrAssign<I> for BitSlice<E, T> | ||
| where E: Endian, T: Bits, I: IntoIterator<Item=bool> { | ||
| where E: crate::Endian, T: crate::Bits, I: IntoIterator<Item=bool> { | ||
| /// `OR`s a bitstream into a slice. | ||
@@ -1075,2 +1164,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1081,2 +1171,3 @@ /// let lhs: &mut BitSlice = &mut bitvec![0, 1, 0, 1, 0, 1]; | ||
| /// assert_eq!("011101", &format!("{}", lhs)); | ||
| /// # } | ||
| /// ``` | ||
@@ -1095,3 +1186,3 @@ fn bitor_assign(&mut self, rhs: I) { | ||
| impl<E, T, I> BitXorAssign<I> for BitSlice<E, T> | ||
| where E: Endian, T: Bits, I: IntoIterator<Item=bool> { | ||
| where E: crate::Endian, T: crate::Bits, I: IntoIterator<Item=bool> { | ||
| /// `XOR`s a bitstream into a slice. | ||
@@ -1102,2 +1193,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1108,5 +1200,6 @@ /// let lhs: &mut BitSlice = &mut bitvec![0, 1, 0, 1, 0, 1]; | ||
| /// assert_eq!("011001", &format!("{}", lhs)); | ||
| /// # } | ||
| /// ``` | ||
| fn bitxor_assign(&mut self, rhs: I) { | ||
| use std::iter::repeat; | ||
| use core::iter::repeat; | ||
| for (idx, other) in (0 .. self.len()).zip(rhs.into_iter().chain(repeat(false))) { | ||
@@ -1122,3 +1215,3 @@ let val = self.get(idx) ^ other; | ||
| impl<'a, E, T> Index<usize> for &'a BitSlice<E, T> | ||
| where E: Endian, T: 'a + Bits { | ||
| where E: crate::Endian, T: 'a + crate::Bits { | ||
| type Output = bool; | ||
@@ -1131,2 +1224,3 @@ | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1137,8 +1231,6 @@ /// let bv = bitvec![0, 0, 1, 0, 0]; | ||
| /// assert!(!bits[3]); | ||
| /// # } | ||
| /// ``` | ||
| fn index(&self, index: usize) -> &Self::Output { | ||
| match self.get(index) { | ||
| true => &TRUE, | ||
| false => &FALSE, | ||
| } | ||
| if self.get(index) { &true} else { &false } | ||
| } | ||
@@ -1153,3 +1245,3 @@ } | ||
| impl<'a, E, T> Index<(usize, u8)> for &'a BitSlice<E, T> | ||
| where E: Endian, T: 'a + Bits { | ||
| where E: crate::Endian, T: 'a + crate::Bits { | ||
| type Output = bool; | ||
@@ -1163,2 +1255,3 @@ | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1170,8 +1263,6 @@ /// let mut bv = bitvec![0; 10]; | ||
| /// assert!(!bits[(1, 1)]); // 9 | ||
| /// # } | ||
| /// ``` | ||
| fn index(&self, (elt, bit): (usize, u8)) -> &Self::Output { | ||
| match self.get(T::join(elt, bit)) { | ||
| true => &TRUE, | ||
| false => &FALSE, | ||
| } | ||
| if self.get(T::join(elt, bit)) { &true } else { &false } | ||
| } | ||
@@ -1201,3 +1292,3 @@ } | ||
| impl<'a, E, T> Neg for &'a mut BitSlice<E, T> | ||
| where E: Endian, T: 'a + Bits { | ||
| where E: crate::Endian, T: 'a + crate::Bits { | ||
| type Output = Self; | ||
@@ -1217,2 +1308,3 @@ | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1222,2 +1314,3 @@ /// let mut num = bitvec![0, 1, 1, 0]; | ||
| /// assert_eq!(num, bitvec![1, 0, 1, 0]); | ||
| /// # } | ||
| /// ``` | ||
@@ -1229,2 +1322,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1234,2 +1328,3 @@ /// let mut num = bitvec![1, 0, 1, 0]; | ||
| /// assert_eq!(num, bitvec![0, 1, 1, 0]); | ||
| /// # } | ||
| /// ``` | ||
@@ -1241,2 +1336,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1249,2 +1345,3 @@ /// let zero = bitvec![0; 10]; | ||
| /// assert_eq!(num, zero); | ||
| /// # } | ||
| /// ``` | ||
@@ -1262,2 +1359,8 @@ fn neg(self) -> Self::Output { | ||
| let addend: &BitSlice<E, T> = { | ||
| // This is safe because an instance of `&[T; 1]` has structure | ||
| // `{ ptr: _, len: 1 }` and that structure when interpreted as | ||
| // an `&BitSlice` refers to a slice of a single bit. Conversion | ||
| // from slice to `BitSlice` is a strictly narrowing operation, | ||
| // and is not a fault. | ||
| #[allow(clippy::transmute_ptr_to_ptr)] | ||
| unsafe { mem::transmute::<&[T], &BitSlice<E, T>>(&elt) } | ||
@@ -1280,3 +1383,3 @@ }; | ||
| impl<'a, E, T> Not for &'a mut BitSlice<E, T> | ||
| where E: Endian, T: 'a + Bits { | ||
| where E: crate::Endian, T: 'a + crate::Bits { | ||
| type Output = Self; | ||
@@ -1289,2 +1392,3 @@ | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1298,2 +1402,3 @@ /// let mut bv = bitvec![0; 10]; | ||
| /// assert_eq!(new_bits.as_ref(), &[!0, !0]); | ||
| /// # } | ||
| /// ``` | ||
@@ -1340,3 +1445,3 @@ fn not(self) -> Self::Output { | ||
| impl<E, T> ShlAssign<usize> for BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| where E: crate::Endian, T: crate::Bits { | ||
| /// Shifts a slice left, in place. | ||
@@ -1347,2 +1452,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1354,3 +1460,7 @@ /// let mut bv = bitvec![1, 1, 1, 0, 0, 0, 0, 0, 1]; | ||
| /// // ^ former tail | ||
| /// # } | ||
| /// ``` | ||
| // Clippy errors when it sees arithmetic ops in an arithmetic impl that are | ||
| // not the operation being implemented. Clippy is, at times, foolish. | ||
| #[allow(clippy::suspicious_op_assign_impl)] | ||
| fn shl_assign(&mut self, shamt: usize) { | ||
@@ -1438,3 +1548,3 @@ let len = self.len(); | ||
| impl<E, T> ShrAssign<usize> for BitSlice<E, T> | ||
| where E: Endian, T: Bits { | ||
| where E: crate::Endian, T: crate::Bits { | ||
| /// Shifts a slice right, in place. | ||
@@ -1445,2 +1555,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1452,3 +1563,7 @@ /// let mut bv = bitvec![1, 0, 0, 0, 0, 0, 1, 1, 1]; | ||
| /// // ^ former head | ||
| /// # } | ||
| /// ``` | ||
| // Clippy errors when it sees arithmetic ops in an arithmetic impl that are | ||
| // not the operation being implemented. Clippy is, at times, foolish. | ||
| #[allow(clippy::suspicious_op_assign_impl)] | ||
| fn shr_assign(&mut self, shamt: usize) { | ||
@@ -1500,3 +1615,3 @@ let len = self.len(); | ||
| pub struct Iter<'a, E, T> | ||
| where E: 'a + Endian, T: 'a + Bits { | ||
| where E: 'a + crate::Endian, T: 'a + crate::Bits { | ||
| inner: &'a BitSlice<E, T>, | ||
@@ -1508,3 +1623,3 @@ head: usize, | ||
| impl<'a, E, T> Iter<'a, E, T> | ||
| where E: 'a + Endian, T: 'a + Bits { | ||
| where E: 'a + crate::Endian, T: 'a + crate::Bits { | ||
| fn reset(&mut self) { | ||
@@ -1517,3 +1632,3 @@ self.head = 0; | ||
| impl<'a, E, T> DoubleEndedIterator for Iter<'a, E, T> | ||
| where E: 'a + Endian, T: 'a + Bits { | ||
| where E: 'a + crate::Endian, T: 'a + crate::Bits { | ||
| fn next_back(&mut self) -> Option<Self::Item> { | ||
@@ -1532,3 +1647,3 @@ if self.tail > self.head { | ||
| impl<'a, E, T> ExactSizeIterator for Iter<'a, E, T> | ||
| where E: 'a + Endian, T: 'a + Bits { | ||
| where E: 'a + crate::Endian, T: 'a + crate::Bits { | ||
| fn len(&self) -> usize { | ||
@@ -1540,3 +1655,3 @@ self.tail - self.head | ||
| impl<'a, E, T> From<&'a BitSlice<E, T>> for Iter<'a, E, T> | ||
| where E: 'a + Endian, T: 'a + Bits { | ||
| where E: 'a + crate::Endian, T: 'a + crate::Bits { | ||
| fn from(src: &'a BitSlice<E, T>) -> Self { | ||
@@ -1553,3 +1668,3 @@ let len = src.len(); | ||
| impl<'a, E, T> Iterator for Iter<'a, E, T> | ||
| where E: 'a + Endian, T: 'a + Bits { | ||
| where E: 'a + crate::Endian, T: 'a + crate::Bits { | ||
| type Item = bool; | ||
@@ -1579,5 +1694,7 @@ | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
| /// let bv = bitvec![BigEndian, u8; 0, 1, 0, 1, 0]; | ||
| /// assert_eq!(bv.iter().count(), 5); | ||
| /// # } | ||
| /// ``` | ||
@@ -1596,2 +1713,3 @@ fn count(self) -> usize { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1602,2 +1720,3 @@ /// let bv = bitvec![BigEndian, u8; 0, 0, 0, 1]; | ||
| /// assert!(bv_iter.nth(3).unwrap()); | ||
| /// # } | ||
| /// ``` | ||
@@ -1613,2 +1732,3 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
@@ -1620,2 +1740,3 @@ /// let bv = bitvec![BigEndian, u8; 0, 0, 0, 1]; | ||
| /// assert!(bv_iter.nth(0).unwrap()); | ||
| /// # } | ||
| /// ``` | ||
@@ -1632,5 +1753,7 @@ fn nth(&mut self, n: usize) -> Option<bool> { | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
| /// let bv = bitvec![BigEndian, u8; 0, 0, 0, 1]; | ||
| /// assert!(bv.into_iter().last().unwrap()); | ||
| /// # } | ||
| /// ``` | ||
@@ -1641,5 +1764,7 @@ /// | ||
| /// ```rust | ||
| /// # #[cfg(feature = "alloc")] { | ||
| /// use bitvec::*; | ||
| /// let bv = bitvec![]; | ||
| /// assert!(bv.into_iter().last().is_none()); | ||
| /// # } | ||
| /// ``` | ||
@@ -1646,0 +1771,0 @@ fn last(mut self) -> Option<bool> { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display