derive macro

This commit is contained in:
2024-04-03 23:56:14 -04:00
parent 61b34768e6
commit e283a36945
2 changed files with 72 additions and 7 deletions

View File

@@ -1,6 +1,5 @@
use std::u16;
use anyhow::{Ok, Result};
pub use poppable_derive::PushPopParse;
//pub type BytesRef = AsRef<u8>;
@@ -236,3 +235,28 @@ flt_impl_pop_non_ne!(f32);
core_impl_pop_ne!(f64);
flt_impl_pop_non_ne!(f64);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let mut s: &[u8] = &vec![4, 8, 15, 16, 23, 42];
let ans = u8::pop_ne_from(&mut s).unwrap();
assert_eq!(ans, 4);
}
#[test]
fn derive_test() {
#[derive(PushPopParse)]
struct Thing {
a: u8,
b: u8,
}
let mut s: &[u8] = &vec![4, 8, 15, 16, 23, 42];
let thing = Thing::pop_ne_from(&mut s).unwrap();
assert_eq!(thing.a, 4);
assert_eq!(thing.b, 8);
}
}