Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
[package]
name = "dh"
version = "0.8.1"
edition = "2021"
version = "0.9.0"
edition = "2024"
description = "Data handling in Rust, made easy."
license = "MIT"
repository = "https://github.com/Le0X8/dh"
documentation = "https://docs.rs/dh"
authors = [ "Leonard Lesinski <84378319+Le0X8@users.noreply.github.com>" ]
readme = "README.md"
keywords = [ "data", "files", "read", "write", "rw" ]
categories = [ "data-structures", "encoding", "filesystem", "parsing" ]

[dependencies]

[dev-dependencies]
murmur3 = "0.5.2"
keywords = [ "data", "read", "write", "rw" ]
categories = [ "data-structures", "encoding", "parsing" ]
112 changes: 4 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@
</h1>

<p align="center">
<b>Data handling in Rust, made easy.</b>
<b>Binary data handling in Rust, made easy.</b>
</p>

## Features

- Read and write files in streams
- No unsafe code
- Support for a lot of data types (including variable length integers and custom length integers)
- Read and write u8 vectors
- std::io::Read and std::io::Write implementations for `Readable` and `Writable` (happens automatically as they extend these traits)
- Copying data from a `Readable` to a `Writable`
- Partial read & write access
- std::io::Read and std::io::Write implementations for `ReadVal` and `WriteVal` (happens automatically as they extend these traits)
- Copying data from `ReadVal` to `Write` (chunked and all at once if you want)
- Floating point number support

### Planned features

- Floating point number support
- Zero-cost cloning
- Zero-cost subarray clones
- Reading and writing of data that does not fill a whole byte

<!--
Expand All @@ -45,105 +40,6 @@ cargo add dh

The documentation can be found on [docs.rs](https://docs.rs/dh).

## Usage

### Simple file reading

```rust
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");
}
```

### Simple file writing

```rust
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
}
```

### Open a file in read/write mode

```rust
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");
}
```

### Read and write u8 vectors

#### Recommended: borrowing

##### Immutable borrowing

```rust
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);
}
```

##### Mutable borrowing

```rust
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);
}
```

#### Alternative: moving

```rust
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]);
}
```

### Limit readable space

```rust
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");
}
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Loading