IntoAByte

Trait IntoAByte 

Source
pub trait IntoAByte {
    // Required method
    fn into_a_byte(self) -> u8;
}
Expand description

Build ORed byte from members of tuple of Into that acts as a bit switch.

§Example

Built byte is used to send to a I2C devise for example.

use into_a_byte::*;

enum FunctionA {
    Enabled = 1 << 3,
    Disabled = 0,
}

enum FunctionB {
    Enabled = 1 << 2,
    Disabled = 0,
}

enum FunctionC {
    Enabled = 1 << 1,
    Disabled = 0,
}

enum FunctionD {
    Enabled = 1,
    Disabled = 0,
}

enums_into_u8!(FunctionA, FunctionB, FunctionC, FunctionD);

fn send_to_device(value: (FunctionA, FunctionB, FunctionC, FunctionD)) {
    // A byte for send to a register for example.
    let byte = value.into_a_byte();

    // TODO
}

fn main() {
    send_to_device((
        FunctionA::Enabled,
        FunctionB::Disabled,
        FunctionC::Enabled,
        FunctionD::Enabled,
    ));
}

Required Methods§

Source

fn into_a_byte(self) -> u8

Implementations on Foreign Types§

Source§

impl<A: Into<u8>> IntoAByte for (A,)

Source§

impl<A: Into<u8>, B: Into<u8>> IntoAByte for (A, B)

Source§

impl<A: Into<u8>, B: Into<u8>, C: Into<u8>> IntoAByte for (A, B, C)

Source§

impl<A: Into<u8>, B: Into<u8>, C: Into<u8>, D: Into<u8>> IntoAByte for (A, B, C, D)

Source§

impl<A: Into<u8>, B: Into<u8>, C: Into<u8>, D: Into<u8>, E: Into<u8>> IntoAByte for (A, B, C, D, E)

Source§

impl<A: Into<u8>, B: Into<u8>, C: Into<u8>, D: Into<u8>, E: Into<u8>, F: Into<u8>> IntoAByte for (A, B, C, D, E, F)

Source§

impl<A: Into<u8>, B: Into<u8>, C: Into<u8>, D: Into<u8>, E: Into<u8>, F: Into<u8>, G: Into<u8>> IntoAByte for (A, B, C, D, E, F, G)

Source§

impl<A: Into<u8>, B: Into<u8>, C: Into<u8>, D: Into<u8>, E: Into<u8>, F: Into<u8>, G: Into<u8>, H: Into<u8>> IntoAByte for (A, B, C, D, E, F, G, H)

Implementors§