Skip to content

wheird-lee/try_buf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages