Expand description

A dynamically-sized view into individual bits of a memory region.

You can read the language’s slice module documentation here.

This module defines the BitSlice region, and all of its associated support code.

BitSlice is the primary working type of this crate. It is a wrapper type over [T] which enables you to view, manipulate, and take the address of individual bits in memory. It behaves in every possible respect exactly like an ordinary slice: it is dynamically-sized, and must be held by & or &mut reference, just like [T], and implements every inherent method and trait that [T] does, to the absolute limits of what Rust permits.

The key to BitSlice’s powerful capability is that references to it use a special encoding that store, in addition to the address of the base element and the bit length, the index of the starting bit in the base element. This custom reference encoding has some costs in what APIs are possible – for instance, Rust forbids it from supporting &mut BitSlice[index] = bool write indexing – but in exchange, enables it to be far more capable than any other bit-slice crate in existence.

Because of the volume of code that must be written to match the [T] standard API, this module is organized very differently than the slice implementation in the core and std distribution libraries.

  • the root module slice contains new APIs that have no counterpart in [T]
  • slice/api contains reïmplementations of the [T] inherent methods
  • slice/iter implements all of the iteration capability
  • slice/ops implements the traits in core::ops
  • slice/proxy implements the proxy reference used in place of &mut bool
  • slice/traits implements all other traits not in core::ops
  • lastly, slice/tests contains all the unit tests.

!

Structs

A slice of individual bits, anywhere in memory.

An iterator over a BitSlice in (non-overlapping) chunks (chunk_size bits at a time), starting at the beginning of the slice.

An iterator over a BitSlice in (non-overlapping) chunks (chunk_size bits at a time), starting at the beginning of the slice.

An iterator over a BitSlice in (non-overlapping) mutable chunks (chunk_size bits at a time), starting at the beginning of the slice.

An iterator over a BitSlice in (non-overlapping) mutable chunks (chunk_size bits at a time), starting at the beginning of the slice.

Immutable BitSlice iterator.

Mutable BitSlice iterator.

Enumerates bits in a BitSlice that are set to 1.

Enumerates bits in a BitSlice that are cleared to 0.

An iterator over a BitSlice in (non-overlapping) chunks (chunk_size bits at a time), starting at the end of the slice.

An iterator over a BitSlice in (non-overlapping) chunks (chunk_size bits at a time), starting at the end of the slice.

An iterator over a BitSlice in (non-overlapping) mutable chunks (chunk_size bits at a time), starting at the end of the slice.

An iterator over a BitSlice in (non-overlapping) mutable chunks (chunk_size bits at a time), starting at the end of the slice.

An iterator over subslices separated by bits that match a predicate function, starting from the end of the BitSlice.

An iterator over subslices separated by bits that match a predicate function, starting from the end of the BitSlice.

An iterator over subslices separated by bits that match a predicate function, limited to a given number of splits, starting from the end of the BitSlice.

An iterator over subslices separated by bits that match a predicate function, limited to a given number of splits, starting from the end of the BitSlice.

An iterator over subslices separated by bits that match a predicate function.

An iterator over the mutable subslices which are separated by bits that match pred.

An iterator over subslices separated by bits that match a predicate function, limited to a given number of splits.

An iterator over subslices separated by bits that match a predicate function, limited to a given number of splits.

An iterator over overlapping subslices of length size.

Traits

A helper trait used for indexing operations.

Functions

Converts a reference to T into a BitSlice over one element.

Forms a bit-slice from a bit-pointer and a length.

Performs the same functionality as from_raw_parts, except that a mutable slice is returned.

Performs the same functionality as from_raw_parts, without checking the len argument.

Performs the same functionality as from_raw_parts_mut, without checking the len argument.

Converts a reference to T into a BitSlice over one element.