Module bitvec::slice[][src]

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

BitSlice

A slice of individual bits, anywhere in memory.

Chunks

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

ChunksExact

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

ChunksExactMut

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

ChunksMut

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

Iter

Immutable BitSlice iterator.

IterMut

Mutable BitSlice iterator.

IterOnes

Enumerates bits in a BitSlice that are set to 1.

IterZeros

Enumerates bits in a BitSlice that are cleared to 0.

RChunks

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

RChunksExact

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

RChunksExactMut

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

RChunksMut

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

RSplit

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

RSplitMut

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

RSplitN

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.

RSplitNMut

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.

Split

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

SplitMut

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

SplitN

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

SplitNMut

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

Windows

An iterator over overlapping subslices of length size.

Traits

BitSliceIndex

A helper trait used for indexing operations.

Functions

from_mut

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

from_raw_parts

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

from_raw_parts_mut

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

from_raw_parts_unchecked

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

from_raw_parts_unchecked_mut

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

from_ref

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