Crates.io | dh |
lib.rs | dh |
version | 0.8.1 |
source | src |
created_at | 2024-09-28 19:54:39.141924 |
updated_at | 2024-11-23 18:22:48.035249 |
description | Data handling in Rust, made easy. |
homepage | |
repository | https://github.com/Le0X8/dh |
max_upload_size | |
id | 1390326 |
size | 199,963 |
dh
Data handling in Rust, made easy.
Readable
and Writable
(happens automatically as they extend these traits)Readable
to a Writable
cargo add dh
The documentation can be found on docs.rs.
use dh::recommended::*;
fn main() {
let mut file = dh::file::open_r("data.txt").unwrap();
let size = file.size().unwrap();
assert_eq!(file.read_utf8(size).unwrap(), "Hello, world!\n");
}
use dh::recommended::*;
fn main() {
let mut file = dh::file::open_w("data.txt").unwrap();
file.write_utf8_at("Hello, world!\n", 0).unwrap();
file.close().unwrap(); // optional, but recommended
}
use dh::recommended::*;
fn main() {
let mut file = dh::file::open_rw("data.txt").unwrap();
file.write_utf8_at("Hello, world!\n", 0).unwrap();
file.rewind().unwrap();
let size = file.size().unwrap();
assert_eq!(file.read_utf8(size).unwrap(), "Hello, world!\n");
}
use dh::recommended::*;
fn main() {
let mut data = vec![31u8; 1];
let mut rw = dh::data::read_ref(&data);
assert_eq!(rw.read_u8().unwrap(), 31);
}
use dh::recommended::*;
fn main() {
let mut data = vec![0u8; 1];
let mut rw = dh::data::rw_ref(&mut data);
rw.write_u8(31).unwrap();
rw.rewind().unwrap();
assert_eq!(rw.read_u8().unwrap(), 31);
}
use dh::recommended::*;
fn main() {
let data = vec![0u8; 1];
let mut rw = dh::data::rw(data);
rw.write_u8(31).unwrap();
rw.rewind().unwrap();
assert_eq!(rw.read_u8().unwrap(), 31);
let data = dh::data::close(rw).unwrap();
assert_eq!(data, vec![31]);
}
use dh::recommended::*;
fn main() {
let mut file = dh::file::open_r("data.txt").unwrap();
let mut limited = file.limit(0, 5).unwrap();
assert_eq!(limited.read_utf8(5).unwrap(), "Hello");
}
This project is licensed under the MIT License - see the LICENSE file for details.