Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jwilm/uuidtoa
https://github.com/jwilm/uuidtoa
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jwilm/uuidtoa
- Owner: jwilm
- License: apache-2.0
- Created: 2018-04-15T18:46:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-15T18:50:58.000Z (over 6 years ago)
- Last Synced: 2024-10-17T10:06:53.793Z (21 days ago)
- Language: Rust
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
uuidtoa
=======Optimized serialization of hyphenated UUID ASCII representation to `io::Write`
sinks.The two functions exported by this crate are `write_lower` and `write_upper`;
here are their signatures:```rust
fn write_lower(io: &mut W, uuid: &Uuid) -> io::Result;
fn write_upper(io: &mut W, uuid: &Uuid) -> io::Result;
```An example of writing this out to a buffer would be
```rust
let uuid = Uuid::from_str("e098d1f6-7e49-4c34-99f6-e9c6cef8fcce").unwrap();
let mut buf: Vec = Vec::with_capacity(36);
write_lower(&mut buf, &uuid).unwrap();
```This performs approximately 10x better than the equivalent `fmt::Display` impl
from the _uuid_ crate.```rust
let uuid = Uuid::from_str("e098d1f6-7e49-4c34-99f6-e9c6cef8fcce").unwrap();
let buf = format!("{}", uuid.hyphenated());
```The benchmarks from these two approaches are as follows.
```
test benches::bench_fmt ... bench: 522 ns/iter (+/- 6)
test benches::bench_lower ... bench: 45 ns/iter (+/- 0)
```To run them for yourself, the bench feature and nightly compiler should be used.
```sh
cargo bench --feature bench
```