Skip to content

Commit f738b34

Browse files
committed
feat: replace bitflags dependency with custom implementation
1 parent c624487 commit f738b34

3 files changed

Lines changed: 47 additions & 15 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ edition = "2024"
1313
rust-version = "1.85.0"
1414

1515
[dependencies]
16-
bitflags = { version = "2", default-features = false }
1716
serde = { version = "1", optional = true }
1817

1918
[dev-dependencies]

src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
#![allow(clippy::cast_ptr_alignment)]
2727
#![cfg_attr(not(feature = "std"), no_std)]
2828

29-
#[macro_use]
30-
extern crate bitflags;
31-
#[cfg(test)]
32-
extern crate rand;
33-
3429
#[macro_use]
3530
extern crate alloc;
3631

src/node.rs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,55 @@ macro_rules! assert_some {
1515
};
1616
}
1717

18-
bitflags! {
19-
#[derive(Clone, Copy)]
20-
pub (crate) struct Flags: u8 {
21-
const VALUE_ALLOCATED = 0b0000_0001;
22-
const VALUE_INITIALIZED = 0b0000_0010;
18+
#[derive(Clone, Copy)]
19+
pub(crate) struct Flags(u8);
20+
21+
impl Flags {
22+
pub const VALUE_ALLOCATED: Flags = Flags(0b0000_0001);
23+
pub const VALUE_INITIALIZED: Flags = Flags(0b0000_0010);
24+
pub const CHILD_ALLOCATED: Flags = Flags(0b0000_0100);
25+
pub const CHILD_INITIALIZED: Flags = Flags(0b0000_1000);
26+
pub const SIBLING_ALLOCATED: Flags = Flags(0b0001_0000);
27+
pub const SIBLING_INITIALIZED: Flags = Flags(0b0010_0000);
28+
29+
pub const fn empty() -> Self {
30+
Flags(0)
31+
}
32+
33+
pub const fn from_bits_truncate(bits: u8) -> Self {
34+
Flags(bits)
35+
}
36+
37+
pub const fn bits(self) -> u8 {
38+
self.0
39+
}
40+
41+
pub const fn contains(self, other: Flags) -> bool {
42+
(self.0 & other.0) == other.0
43+
}
44+
45+
pub const fn intersects(self, other: Flags) -> bool {
46+
(self.0 & other.0) != 0
47+
}
48+
49+
pub fn insert(&mut self, other: Flags) {
50+
self.0 |= other.0;
51+
}
52+
53+
pub fn set(&mut self, other: Flags, value: bool) {
54+
if value {
55+
self.0 |= other.0;
56+
} else {
57+
self.0 &= !other.0;
58+
}
59+
}
60+
}
2361

24-
const CHILD_ALLOCATED = 0b0000_0100;
25-
const CHILD_INITIALIZED = 0b0000_1000;
62+
impl core::ops::BitOr for Flags {
63+
type Output = Self;
2664

27-
const SIBLING_ALLOCATED = 0b0001_0000;
28-
const SIBLING_INITIALIZED = 0b0010_0000;
65+
fn bitor(self, other: Self) -> Self {
66+
Flags(self.0 | other.0)
2967
}
3068
}
3169

0 commit comments

Comments
 (0)