Skip to content

Commit 64876d1

Browse files
committed
Update README.md with new bitmap API
1 parent d54692b commit 64876d1

1 file changed

Lines changed: 26 additions & 31 deletions

File tree

README.md

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ of the definition, with automatically generated getters and setters for each fie
4747
```rust
4848
use bitmap::bitmap;
4949

50-
bitmap!(
51-
struct Player {
52-
imposter: u1,
53-
finished_tasks: u3,
54-
kills: u3,
55-
}
56-
);
50+
#[bitmap]
51+
struct Player {
52+
imposter: u1,
53+
finished_tasks: u3,
54+
kills: u3,
55+
}
5756

5857
let mut player = Player(0);
5958
assert_eq!(std::mem::size_of::<Player>(), 1);
@@ -87,13 +86,12 @@ the following traits are implemented:
8786
```rust
8887
use bitmap::bitmap;
8988

90-
bitmap!(
91-
struct Bits {
92-
a: u32,
93-
b: u16,
94-
c: u16,
95-
}
96-
);
89+
#[bitmap]
90+
struct Bits {
91+
a: u32,
92+
b: u16,
93+
c: u16,
94+
}
9795

9896
let bits = Bits(0);
9997
let underlying_u64: u64 = bits.into();
@@ -105,12 +103,11 @@ let underlying_u64 = *bits;
105103
```rust
106104
use bitmap::bitmap;
107105

108-
bitmap!(
109-
struct Bits {
110-
flag: u1,
111-
counter: u7,
112-
}
113-
);
106+
#[bitmap]
107+
struct Bits {
108+
flag: u1,
109+
counter: u7,
110+
}
114111
```
115112

116113
Each field must be in the form `uN`, where `1 <= N <= 128`.
@@ -131,12 +128,11 @@ This means the first declared field is stored in the highest bits of the underly
131128
```rust
132129
use bitmap::bitmap;
133130

134-
bitmap!(
135-
struct Bits {
136-
a: u8,
137-
b: u8,
138-
}
139-
);
131+
#[bitmap]
132+
struct Bits {
133+
a: u8,
134+
b: u8,
135+
}
140136

141137
let mut bits = Bits(0);
142138
bits.set_a(0xaa)
@@ -154,11 +150,10 @@ field will take up 64 bits of space.
154150
```rust
155151
use bitmap::bitmap;
156152

157-
bitmap!(
158-
struct Bits {
159-
field: u33,
160-
}
161-
);
153+
#[bitmap]
154+
struct Bits {
155+
field: u33,
156+
}
162157

163158
assert_eq!(core::mem::size_of::<Bits>(), 8);
164159
```

0 commit comments

Comments
 (0)