Crates.io | rw-utils |
lib.rs | rw-utils |
version | 0.0.1 |
source | src |
created_at | 2024-03-04 19:21:44.103127 |
updated_at | 2024-03-04 19:21:44.103127 |
description | Collection of utilities that enhance the rust Read and Write traits by providing various utility method for reading/writing structured data. |
homepage | https://github.com/AlexanderSchuetz97/rw-utils |
repository | |
max_upload_size | |
id | 1162189 |
size | 129,836 |
Collection of utilities that enhance the rust Read and Write traits by providing various utility method for reading/writing structured data.
This example uses File for the implementation of Read or Write. You can do this with any impl of
these traits. Vec<u8>
/Cursor
/...
use std::io;
use rw_utils::num_read::NumRead;
use rw_utils::num_write::NumWrite;
fn main() -> io::Result<()> {
let mut file = File::create("/tmp/somefile")?;
//Write u16 in little endian
file.write_u16_le(0x4418u16)?;
//Write u16 in big endian
file.write_u16_be(0x4418u16)?;
drop(file);
let mut file = File::open("/tmp/somefile")?;
//Read u16 in little endian
assert_eq!(file.read_u16_le()?, 0x4418u16);
//Read u16 in big endian
assert_eq!(file.read_u16_be()?, 0x4418u16);
return Ok(());
}
To reduce "size" of the binary when using this library the default feature is empty. In order for this library to do anything you need to add at least 1 out of the following list of features:
If you want all features you can add the "all" feature.
[dependencies]
rw-utils = {version = "*", features = ["all"]}