#buf #byte #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 5/week @ 2024-07-24 8/week @ 2024-07-31 12/week @ 2024-08-07 8/week @ 2024-08-14 8/week @ 2024-08-21 12/week @ 2024-08-28 1/week @ 2024-09-04 7/week @ 2024-09-11 34/week @ 2024-09-18 90/week @ 2024-09-25 46/week @ 2024-10-02 28/week @ 2024-10-09 17/week @ 2024-10-16 62/week @ 2024-10-23 42/week @ 2024-10-30

161 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