Skip to content

Commit 053c9b4

Browse files
committed
✨ Impl Debug and ignore 0 bit members
1 parent 71936ee commit 053c9b4

File tree

5 files changed

+152
-90
lines changed

5 files changed

+152
-90
lines changed

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bitfield-struct"
3-
version = "0.1.7"
3+
version = "0.1.8"
44
edition = "2021"
55
authors = ["Lars Wrenger <lars@wrenger.net>"]
66
description = "Procedural macro for bitfields."

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![API](https://docs.rs/bitfield-struct/badge.svg)](https://docs.rs/bitfield-struct)
55

66
Procedural macro for bitfields that allows specifying bitfields as structs.
7-
As this library provides a procedural-macro it has no runtime dependencies and works for `no-std`.
7+
As this library provides a procedural macro, it has no runtime dependencies and works for `no-std`.
88

99
## Usage
1010

@@ -43,9 +43,10 @@ struct PageTableEntry {
4343
The macro generates three accessor functions for each field.
4444
Each accessor also inherits the documentation of its field.
4545

46-
The signatures for `addr` for example are:
46+
The signatures for `addr`, for example, are:
4747

4848
```rust
49+
// generated struct
4950
struct PageTableEntry(u64);
5051
impl PageTableEntry {
5152
const fn new() -> Self { /* ... */ }
@@ -54,25 +55,28 @@ impl PageTableEntry {
5455
const fn addr(&self) -> u32 { /* ... */ }
5556
fn set_addr(&mut self, value: u32) { /* ... */ }
5657

57-
// other members ...
58+
// other fields ...
5859
}
60+
// generated trait implementations
5961
impl From<u64> for PageTableEntry { /* ... */ }
6062
impl From<PageTableEntry> for u64 { /* ... */ }
63+
impl Debug for PageTableEntry { /* ... */ }
6164
```
6265

63-
This generated bitfield then can be used as follows.
66+
This generated bitfield can then be used as follows.
6467

6568
```rust
66-
let pte = PageTableEntry::new()
69+
let mut pte = PageTableEntry::new()
6770
.with_addr(3 << 31)
6871
.with_size(2)
6972
.with_present(false)
7073
.with_negative(-3);
7174

72-
println!("{}", pte.addr());
75+
println!("{pte:?}");
76+
assert!(pte.addr() == 3 << 31);
7377

7478
pte.set_size(1);
7579

7680
let value: u64 = pte.into();
77-
println!("{:b}", value);
81+
println!("{value:b}");
7882
```

0 commit comments

Comments
 (0)