Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vonr/barf
Turn any input into "barf"-ed output.
https://github.com/vonr/barf
Last synced: about 1 month ago
JSON representation
Turn any input into "barf"-ed output.
- Host: GitHub
- URL: https://github.com/vonr/barf
- Owner: Vonr
- Created: 2023-09-25T14:23:43.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-09-25T14:24:54.000Z (over 1 year ago)
- Last Synced: 2024-08-10T10:51:36.553Z (5 months ago)
- Language: Rust
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Barf
Turn any input into "barf"-ed output.
The name is a play on the purpose of this crate as a deparser - the opposite of the fantastic [nom](https://github.com/rust-bakery/nom) crate.
Barf aims to have some integrations with common datatypes such as [LEB128 encoded variable-length integers](https://en.wikipedia.org/wiki/LEB128).
When these integrations require another crate, they will be locked behind feature flags.These integrations include
- LEB128 with the "leb128" feature flag using [nano-leb128](https://crates.io/crates/nano-leb128).
- [vint64](https://crates.io/crates/vint64) with the "vint64" feature flag.For a full list, see [Cargo.toml](https://github.com/Vonr/barf/blob/master/Cargo.toml).
If you want to see more integrations, please open an issue, or preferably a pull request.
There is also nothing stopping you from implementing [`Barfer`] on your own types and creating extension traits for them.Barf can operate in no_std environments, but the "alloc" feature flag needs to be enabled for the default implementations of [`Barfer`] for [`Vec`] and [`String`].
```rust
use barf::Barfer;// Vec implements Barfer.
let mut buf: Vec = Vec::new();// Push 42_u8
buf.single(42);
// Push "test".bytes() iterator with `many`
buf.many("test".bytes());
// Push 1, 2, and 3
buf.slice([1, 2, 3]);assert_eq!(
&buf[..],
[
42, // 42_u8
116, 101, 115, 116, // Bytes in "test"
1, 2, 3, // 1, 2, and 3
]
);
```