#byte #buf #api #try #no-panic #mentioned

try_buf

This crate provides no-panic API for bytes::Buf

3 releases

0.1.3 Mar 5, 2023
0.1.2 Feb 3, 2023
0.1.1 Feb 3, 2023
0.1.0 Aug 14, 2022

#3 in #no-panic

Download history 22/week @ 2024-07-01 1/week @ 2024-07-08 13/week @ 2024-07-29 19/week @ 2024-08-12 4/week @ 2024-08-19 17/week @ 2024-08-26 8/week @ 2024-09-09 93/week @ 2024-09-23 61/week @ 2024-09-30 32/week @ 2024-10-07 24/week @ 2024-10-14

210 downloads per month
Used in 2 crates (via impeller)

MIT license

10KB
260 lines

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());

lib.rs:

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

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());

Dependencies

~180KB