pub struct Pack32<T = u32, F = ()> { /* private fields */ }
Expand description

A spec for packing values into selected bit ranges of u32 values.

See the module-level documentation for details on using packing specs.

Implementations

Wrap a u32 to add methods for packing bit ranges using Pack32.

This is equivalent to calling Packing32::new, but only requires importing the packer type.

Returns a packer for packing a value into the first bits bits.

Returns a packer that will pack a value into the provided mask.

This is a const fn-compatible equivalent of Self::from_range. Note that it can only be used with core::ops::Ranges, and not with core::ops::RangeInclusive, core::ops::RangeTo, core::ops::RangeFrom, core::ops::RangeToInclusive. :(

Construct a bit packing spec from a range of bits.

Panics
  • If the range does not fit within the integer type packed by this packing spec.
  • If the range’s start > the range’s end (although most range types should prevent this).

Returns a packer for packing a value into the next n more-significant after the bitth bit.

Returns the number of bits needed to pack this value.

Returns the maximum value of this packing spec (i.e. a value with all the bits set)

Returns a value with the first bit in this packing spec set.

Returns a raw, shifted mask for unpacking this packing spec.

Pack the self.bits() least-significant bits from value into base.

Any bits more significant than the self.bits()-th bit are ignored.

Pack the self.bits() least-significant bits from value into base, mutating base.

Any bits more significant than the self.bits()-th bit are ignored.

Returns a new packer for packing a T2-typed value in the next T2::BITS bits after self.

Returns a packer for packing a value into the next more-significant n from self.

Returns a packer for packing a value into all the remaining more-significant bits after self.

Set all bits packed by this packer to 1.

This is a convenience function for

self.pack(self.max_value(), base)

Set all bits packed by this packer to 0.

This is a convenience function for

self.pack(0, base)

Set all bits packed by this packer to 1 in base.

This is a convenience function for

self.pack_into(self.max_value(), base)

Set all bits packed by this packer to 0.

This is a convenience function for

self.pack_into(0, base)

Unpack this packer’s bits from source.

Returns true if any bits specified by this packing spec are set in src.

Returns true if all bits specified by this packing spec are set in src.

Asserts that this packing spec is valid.

Because assertions cannot be made in const fn, this performs validating assertions that would ideally be made when constructing a new instance of this type. When packing specs are declared as consts, this method can be called in a unit test to ensure that the spec is valid.

Assert all of a set of packing specs are valid for packing and unpacking values into the same bitfield.

This asserts that each individual packing spec is valid (by calling assert_valid on that spec), and asserts that no two packing specs in specs overlap (indicating that they can safely represent a single bitfield’s subranges).

This function takes a slice of (&str, Self) tuples, with the &strs providing a name for each packing spec. This name is used to refer to that packing spec in panic messages.

Returns the index of the least-significant bit of this packing spec (i.e. the bit position of the start of the packed range).

Returns the index of the most-significant bit of this packing spec (i.e. the bit position of the end of the packed range).

This will always be greater than the value returned by least_significant_index.

Returns a packing spec for packing a T-typed value in the first T::BITS least-significant bits.

Returns a pair type for packing bits from the range specified by self at the specified offset at, which may differ from self’s offset.

The packing pair can be used to pack bits from one location into another location, and vice versa.

Returns a pair type for packing bits from the range specified by self after the specified packing spec.

Pack the self.bits() least-significant bits from value into base.

Panics

Panics if any other bits outside of self.bits() are set in value.

Pack the self.bits() least-significant bits from value into base, mutating base.

Panics

Panics if any other bits outside of self.bits() are set in value.

Attempts to unpack a T-typed value from src.

Returns
  • Ok(T) if a T-typed value could be constructed from the bits in src
  • Err(T::Error) if src does not contain a valid bit pattern for a T-typed value, as determined by T’s FromBits::try_from_bits implementation.

Unpacks a T-typed value from src.

Panics

This method panics if src does not contain a valid bit pattern for a T-typed value, as determined by T’s FromBits::try_from_bits implementation.

Trait Implementations

Formats the value using the given formatter.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Formats the value using the given formatter.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Formats the value using the given formatter.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.