try_buf

Crates.iotry_buf
lib.rstry_buf
version0.1.3
sourcesrc
created_at2022-08-14 02:37:02.233574
updated_at2023-03-05 18:27:10.904639
descriptionThis crate provides no-panic API for bytes::Buf
homepage
repositoryhttps://github.com/wheird-lee/try_buf
max_upload_size
id645160
size10,734
(wheird-lee)

documentation

README

This crate provides no-panic API for any type T impl bytes::Buf, which is mentioned in issue#254.

issues and PRs are welcome.

example

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());
Commit count: 10

cargo fmt