Skip to content

Commit

Permalink
Revert some more docs to from_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
wcampbell0x2a authored and sharksforarms committed Nov 16, 2023
1 parent f227e8b commit 934b42c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use alloc::format;
use alloc::string::String;

/// Number of bits needed to retry parsing
///
/// TODO: add bytes
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NeedSize {
bits: usize,
Expand Down
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,15 @@ struct DekuHeader(u8);
#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct DekuData(u16);
let data: &[u8] = &[0xAA, 0xEF, 0xBE];
let mut cursor = Cursor::new(data);
let (_amt_read, mut val) = DekuTest::from_reader((&mut cursor, 0)).unwrap();
let data: Vec<u8> = vec![0xAA, 0xEF, 0xBE];
let (_rest, mut val) = DekuTest::from_bytes((data.as_ref(), 0)).unwrap();
assert_eq!(DekuTest {
header: DekuHeader(0xAA),
data: DekuData(0xBEEF),
}, val);
let data_out = val.to_bytes().unwrap();
assert_eq!(data, &*data_out);
assert_eq!(data, data_out);
```
# Vec
Expand All @@ -116,9 +115,8 @@ struct DekuTest {
data: Vec<u8>,
}
let data = vec![0x02, 0xBE, 0xEF, 0xFF, 0xFF];
let mut cursor = Cursor::new(data);
let (_amt_read, mut val) = DekuTest::from_reader((&mut cursor, 0)).unwrap();
let data: Vec<u8> = vec![0x02, 0xBE, 0xEF, 0xFF, 0xFF];
let (_rest, mut val) = DekuTest::from_bytes((data.as_ref(), 0)).unwrap();
assert_eq!(DekuTest {
count: 0x02,
data: vec![0xBE, 0xEF]
Expand Down

0 comments on commit 934b42c

Please sign in to comment.