feat: container tests

This commit is contained in:
davidon-top 2023-12-29 23:07:56 +01:00
parent 6dc79f7e29
commit 0b1486aeee
Signed by: DavidOnTop
GPG key ID: FAB914DDC2F180EB
3 changed files with 339 additions and 316 deletions

View file

@ -3,6 +3,8 @@
This crate aims to make working with binary/bit flags easier. It also provides a macro to add similar functionality to zig's packed structs with boolean fields.
*/
use std::ops::{Deref, DerefMut};
pub use binf_macros::*;
/// A trait for types that can be used as bit flags.
@ -218,3 +220,17 @@ impl<T: BitFlag> BitFlags<T> {
self.0.set_flags(flags);
}
}
impl<T: BitFlag> Deref for BitFlags<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T: BitFlag> DerefMut for BitFlags<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

7
tests/container.rs Normal file
View file

@ -0,0 +1,7 @@
use binf::BitFlags;
#[test]
fn standalone() {
let flags = BitFlags::<u8>::new(0b10101010);
assert_eq!(*flags, 0b10101010);
}