Crates.io | diff-in-place |
lib.rs | diff-in-place |
version | 0.1.2 |
source | src |
created_at | 2023-10-27 17:16:36.338735 |
updated_at | 2023-10-27 19:37:26.184942 |
description | A no_std, zero-copy, in-place diff trait for constant sized arrays |
homepage | |
repository | https://github.com/botanica-consulting/diff-in-place |
max_upload_size | |
id | 1016254 |
size | 12,308 |
A lightweight, Rust idiomatic trait for comparing two constant size arrays in-place and with no copies. Each non-equal run inside the two arrays results in the callback being invoked with the starting index and the different bytes.
This is useful for embedded environments, for instance when updating the state of integrated chip over a peripheral bus such as I2c/SMBus.
This crate is suitable for usage in no_std
targets.
use diff_in_place::DiffInPlace;
// In this scenario you want to update the state on the chip without sending all 7 bytes
let state_on_chip = [0, 0, 1, 1, 1, 1, 1];
let mut new_state = state.clone()
new_state[6] = 0;
state_on_chip.diff_in_place(new_state, |i, data| {
// i = 6
// data = [0,]
peripheral.write_at(i, data);
});
Disclaimer: This library is not an official product, use freely at your own risk.