diff-in-place

Crates.iodiff-in-place
lib.rsdiff-in-place
version0.1.2
sourcesrc
created_at2023-10-27 17:16:36.338735
updated_at2023-10-27 19:37:26.184942
descriptionA no_std, zero-copy, in-place diff trait for constant sized arrays
homepage
repositoryhttps://github.com/botanica-consulting/diff-in-place
max_upload_size
id1016254
size12,308
Alon Livne (0xa10)

documentation

README

diff-in-place

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.

Example

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.

Commit count: 11

cargo fmt