Trait bitfield_layout::BitFieldLayout[][src]

pub trait BitFieldLayout: Layout {
    type Value: Copy + IntoBits + FromBits;
    fn get(&self) -> Self::Value;
fn set(&mut self, new: Self::Value); fn replace(&mut self, new: Self::Value) -> Self::Value { ... }
fn swap(&mut self, other: &mut Self) { ... }
fn update<F>(&mut self, f: F) -> Self::Value
    where
        F: FnOnce(Self::Value) -> Self::Value
, { ... }
fn insert_flag(&mut self, position: usize, b: bool) -> bool { ... }
fn toggle_flag(&mut self, position: usize) { ... }
fn bits(&self) -> Bits<<Self::Value as IntoBits>::Bytes>

Notable traits for Bits<I>

impl<I: Iterator<Item = u8>> Iterator for Bits<I> type Item = bool;
{ ... }
fn flags(
        &self
    ) -> Flags<Self::Layout, Bits<<Self::Value as IntoBits>::Bytes>>

Notable traits for Flags<L, B>

impl<L, B> Iterator for Flags<L, B> where
    L: Iterator,
    B: Iterator<Item = bool>, 
type Item = Flag<L::Item>;
{ ... }
fn diff(
        &self,
        other: Self
    ) -> Diff<Self::Layout, Bits<<Self::Value as IntoBits>::Bytes>>

Notable traits for Diff<L, B>

impl<L, T, B> Iterator for Diff<L, B> where
    L: Iterator<Item = T>,
    B: Iterator<Item = bool>, 
type Item = Either<(usize, T), (usize, T)>;

    where
        Self: Sized
, { ... } }
Expand description

Main trait for creating bitfield

In general you need implement this trait and its dependencies: Layout. This trait already implemented for BitField.

Associated Types

Required methods

fn get(&self) -> Self::Value[src]

Returns a copy of the contained value.

fn set(&mut self, new: Self::Value)[src]

Sets the contained value.

Provided methods

fn replace(&mut self, new: Self::Value) -> Self::Value[src]

Replaces the contained value with val, and returns the old contained value.

let mut simple = Simple(42);

assert_eq!(42, simple.replace(13));
assert_eq!(13, simple.get());

fn swap(&mut self, other: &mut Self)[src]

Swaps the values of two bitfields.

let mut one = Simple(1);
let mut two = Simple(2);

one.swap(&mut two);

assert!(one.get() == 2 && two.get() == 1);

fn update<F>(&mut self, f: F) -> Self::Value where
    F: FnOnce(Self::Value) -> Self::Value
[src]

Updates the contained value using a function and returns the new value.

let mut simple = Simple(1111111111);

assert_eq!(2222222222, simple.update(|x| x * 2));
assert_eq!(2222222222, simple.get());

fn insert_flag(&mut self, position: usize, b: bool) -> bool[src]

Set the specified bit (flag) in-place. Returns current state

let mut simple = Simple(0b10011001);

assert_eq!(false, simple.insert_flag(2, true));
assert_eq!(0b10011101, simple.get());

fn toggle_flag(&mut self, position: usize)[src]

The specified bit (flag) will be inverted

let mut simple = Simple(0b10011001);

simple.toggle_flag(0);

assert_eq!(0b10011000, simple.get());

fn bits(&self) -> Bits<<Self::Value as IntoBits>::Bytes>

Notable traits for Bits<I>

impl<I: Iterator<Item = u8>> Iterator for Bits<I> type Item = bool;
[src]

Return iterator through bitfield value bits. Every bit represents as bool value.

let mut simple = Simple(0b01010101);

assert!(simple.bits().step_by(2).all(|v| v == true));

fn flags(&self) -> Flags<Self::Layout, Bits<<Self::Value as IntoBits>::Bytes>>

Notable traits for Flags<L, B>

impl<L, B> Iterator for Flags<L, B> where
    L: Iterator,
    B: Iterator<Item = bool>, 
type Item = Flag<L::Item>;
[src]

Return iterator through bitfield value flags. Every flag contains bit state (set or unset) and item (record) value - string in simple case.

struct Simple(u8);
impl Layout for Simple {
    type Layout = slice::Iter<'static, &'static str>;
    fn layout() -> Self::Layout {
        [
            "First",
            "Second",
            "Third",
            "Fourth",
            "Fifth",
            "Sixth",
            "Seventh",
            "Eighth",
        ].iter()
    }
}
let mut simple = Simple(0b01010101);

assert_eq!(Flag { is_set: true, value: &"First"}, simple.flags().next().unwrap());

fn diff(
    &self,
    other: Self
) -> Diff<Self::Layout, Bits<<Self::Value as IntoBits>::Bytes>>

Notable traits for Diff<L, B>

impl<L, T, B> Iterator for Diff<L, B> where
    L: Iterator<Item = T>,
    B: Iterator<Item = bool>, 
type Item = Either<(usize, T), (usize, T)>;
where
    Self: Sized
[src]

Helps to find difference between two bitfield values.

struct Simple(u8);
impl Layout for Simple {
    type Layout = slice::Iter<'static, &'static str>;
    fn layout() -> Self::Layout {
        [
            "First",
            "Second",
            "Third",
            "Fourth",
            "Fifth",
            "Sixth",
            "Seventh",
            "Eighth",
        ].iter()
    }
}
let mut left =  Simple(0b01010101);
let mut right = Simple(0b01010001);

assert_eq!(vec![Either::Left((2, &"Third"))], left.diff(right).collect::<Vec<_>>());

Implementors

impl<M: Layout, T: Copy + IntoBits + FromBits> BitFieldLayout for BitField<M, T>[src]

type Value = T

fn get(&self) -> Self::Value[src]

fn set(&mut self, new: Self::Value)[src]