#slice #reference #write #value #write-access #read-access

no-std write-only

References/slices that provide write-access, but no read-access

1 unstable release

0.1.0 Oct 26, 2021

#2958 in Rust patterns

MPL-2.0 license

37KB
581 lines

write-only

Checks Downloads Version License

Synopsis

Rust references/slices that provide write-access, but no read-access.

Motivation

Sometimes is is desirable to only provide write-access to a value or slice of values without also providing read-access..

This is where write-only comes in handy!

Usage

Write-only reference:

use write_only::{prelude::*, Put};

fn write<T: Put<u8>>(write_only: &mut T) {
    write_only.put(42u8);
}

let mut value: u8 = 0;

let mut write_only = WriteOnlyRef::from(&mut value);
write(&mut write_only);

assert_eq!(value, 42);

Write-only slice:

use write_only::{prelude::*, PutAt};

fn write<T: PutAt<u8>>(write_only: &mut T) {
    write_only.put_at(2, 42u8);
}

let mut values: Vec<u8> = (0..10).collect();

let mut write_only = WriteOnlySlice::from(&mut values[..]);
write(&mut write_only);

assert_eq!(values[2], 42u8);

Contributing

Please read CONTRIBUTING.md for details on our code of conduct,
and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MPL-2.0 – see the LICENSE.md file for details.

No runtime deps