Crates.io | write-only |
lib.rs | write-only |
version | 0.1.0 |
source | src |
created_at | 2021-10-26 23:07:00.322229 |
updated_at | 2021-10-26 23:07:00.322229 |
description | References/slices that provide write-access, but no read-access. |
homepage | |
repository | https://github.com/regexident/write-only |
max_upload_size | |
id | 472210 |
size | 57,838 |
Rust references/slices that provide write-access, but no read-access.
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!
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);
Please read CONTRIBUTING.md for details on our code of conduct,
and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the MPL-2.0 – see the LICENSE.md file for details.