File tree 1 file changed +8
-4
lines changed
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -97,10 +97,11 @@ struct MyBitfield {
97
97
/// sign extend for signed integers
98
98
#[bits(13)]
99
99
negative : i16 ,
100
- /// supports any type, with `into`/`from` expressions (that are const eval)
100
+ /// supports any type, with `into_bits`/`from_bits` (const) functions,
101
+ /// if not configured otherwise with the `into`/`from` parameters of the bits attribute.
101
102
///
102
- /// the field is initialized with 0 (passed into `from `) if not specified otherwise
103
- #[bits(16, into = this as _, from = CustomEnum :: from_bits(this) )]
103
+ /// the field is initialized with 0 (passed into `from_bits `) if not specified otherwise
104
+ #[bits(16)]
104
105
custom : CustomEnum ,
105
106
/// public field -> public accessor functions
106
107
#[bits(12)]
@@ -119,7 +120,10 @@ enum CustomEnum {
119
120
C = 2 ,
120
121
}
121
122
impl CustomEnum {
122
- // This has to be const eval
123
+ // This has to be a const fn
124
+ const fn into_bits (self ) -> u64 {
125
+ self as _
126
+ }
123
127
const fn from_bits (value : u64 ) -> Self {
124
128
match value {
125
129
0 => Self :: A ,
You can’t perform that action at this time.
0 commit comments