pub fn set_bits_from_byte(dest: &mut [u8], index: u32, value: u8)Expand description
set_bits_from_byte - set many bits from a single byte value
The set_bits_from_byte() function shall set many bits from a single byte.
All 8 bits from the byte value will be written to dest array starting at index position.
§Parameters
dest- destination sliceindex- starting position where the bit should writtenvalue- set many bits from a single byte. All 8 bits from the bytevaluewill be written todestslice starting atindexposition.
§Examples
use libmodbus::{Modbus, ModbusMapping, ModbusTCP};
use libmodbus::prelude::*;
let modbus = Modbus::new_tcp("127.0.0.1", 1502).unwrap();
let modbus_mapping = ModbusMapping::new(5, 5, 5, 5).unwrap();
// before
assert_eq!(modbus_mapping.get_input_bits_mut(), [0u8, 0, 0, 0, 0]);
set_bits_from_byte(modbus_mapping.get_input_bits_mut(), 2, 0b1111_1111);
// after
assert_eq!(modbus_mapping.get_input_bits_mut(), [0u8, 0, 1, 1, 1]);