| Crates.io | try_buf |
| lib.rs | try_buf |
| version | 0.1.3 |
| created_at | 2022-08-14 02:37:02.233574+00 |
| updated_at | 2023-03-05 18:27:10.904639+00 |
| description | This crate provides no-panic API for bytes::Buf |
| homepage | |
| repository | https://github.com/wheird-lee/try_buf |
| max_upload_size | |
| id | 645160 |
| size | 10,734 |
This crate provides no-panic API for any type T impl bytes::Buf,
which is mentioned in issue#254.
issues and PRs are welcome.
use bytes::{Bytes, Buf};
use try_buf::TryBuf;
let mut bytes = Bytes::from_static(&[1, 2, 3, 4]);
let a = bytes.try_get_u16().unwrap();
assert_eq!(a, 0x0102);
let b = bytes.try_get_u32()
.unwrap_or_else(|e| {
println!("fail to get u32: {}", e);
0
});
assert_eq!(b, 0);
assert_eq!(2, bytes.remaining());