Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zeozeozeo/rwtypes
Adds methods to read/write binary numbers to the Read and Write traits.
https://github.com/zeozeozeo/rwtypes
binary file file-io filesystem filesystems io number numbers read reader rust rust-patterns utils-library write writer
Last synced: 29 days ago
JSON representation
Adds methods to read/write binary numbers to the Read and Write traits.
- Host: GitHub
- URL: https://github.com/zeozeozeo/rwtypes
- Owner: zeozeozeo
- License: unlicense
- Created: 2023-09-12T13:57:51.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-09-12T13:57:54.000Z (over 1 year ago)
- Last Synced: 2024-12-01T00:56:22.951Z (about 1 month ago)
- Topics: binary, file, file-io, filesystem, filesystems, io, number, numbers, read, reader, rust, rust-patterns, utils-library, write, writer
- Language: Rust
- Homepage: https://crates.io/crates/rwtypes
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Adds methods to read/write binary numbers to the `Read` and `Write` traits.
This is a simple crate that adds methods like `read_u8`, `read_u32_le`, `read_u64_be`, `write_i128_le`, `write_u16_be`, ... to the Rust [Read](https://doc.rust-lang.org/std/io/trait.Read.html) and [Write](https://doc.rust-lang.org/std/io/trait.Write.html) traits.
The `impl` feature includes the implementations for the WriterTypes and ReaderTypes traits. It is enabled by default.
# Example
### Reading
```rust
// read u32 (4 bytes) from a file in little endian.
let num = f.read_u32_le().unwrap();
``````rust
// read i64 (8 bytes) from a file in big endian.
let num = f.read_i64_be().unwrap();
```### Writing
```rust
// write u32 (4 bytes) to a file in little endian.
let num = f.write_u32_le(0xdeadbeef).unwrap();
``````rust
// write i128 (16 bytes) to a file in big endian.
let num = f.write_i64_be(12345).unwrap();
```This works with any type that implements [Read](https://doc.rust-lang.org/std/io/trait.Read.html) or [Write](https://doc.rust-lang.org/std/io/trait.Write.html).
# License
Public domain (Unlicense)