3 releases
0.1.3 | Mar 5, 2023 |
---|---|
0.1.2 | Feb 3, 2023 |
0.1.1 |
|
0.1.0 | Aug 14, 2022 |
#3 in #no-panic
161 downloads per month
Used in 2 crates
(via impeller)
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