#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 61/week @ 2024-02-19 23/week @ 2024-02-26 45/week @ 2024-03-04 37/week @ 2024-03-11 14/week @ 2024-03-18 55/week @ 2024-03-25 32/week @ 2024-04-01 14/week @ 2024-04-08 26/week @ 2024-04-15 15/week @ 2024-04-22

89 downloads per month

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

~175KB