Skip to content

Commit

Permalink
Enable specifiers up to B128
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed May 24, 2019
1 parent 118fcfc commit b20828d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion impl/src/define_specifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use quote::{

pub fn generate(_input: TokenStream2) -> TokenStream2 {
let mut tokens = quote!{};
for n in 1usize..=64 {
for n in 1usize..=128 {
let t_origin = match n {
1..=8 => quote!{u8},
9..=16 => quote!{u16},
Expand Down
39 changes: 39 additions & 0 deletions tests/16-u128-specifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Tests bitfield specifiers of more than 64 bit.

use modular_bitfield::prelude::*;

#[bitfield]
pub struct SomeMoreBytes {
a: B47,
b: B65,
c: B128,
}

fn main() {
let mut bitfield = SomeMoreBytes::new();

// Everything is initialized to zero.
assert_eq!(bitfield.get_a(), 0);
assert_eq!(bitfield.get_b(), 0);
assert_eq!(bitfield.get_c(), 0);

// Manipulate bitfield.
assert_eq!(bitfield.set_a_checked(1), Ok(()));
assert_eq!(bitfield.set_b_checked(3), Ok(()));
assert_eq!(bitfield.set_c_checked(42), Ok(()));

// Check that manipulation was successful.
assert_eq!(bitfield.get_a(), 1);
assert_eq!(bitfield.get_b(), 3);
assert_eq!(bitfield.get_c(), 42);

// // Manually reset the bitfield.
bitfield.set_a(0);
bitfield.set_b(0);
bitfield.set_c(0);

// // Check if reset was successful.
assert_eq!(bitfield.get_a(), 0);
assert_eq!(bitfield.get_b(), 0);
assert_eq!(bitfield.get_c(), 0);
}
1 change: 1 addition & 0 deletions tests/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ fn tests() {
t.pass("tests/13-tuple-structs.rs");
t.pass("tests/14-checked-setters.rs");
t.pass("tests/15-manual-reset.rs");
t.pass("tests/16-u128-specifier.rs");
}

0 comments on commit b20828d

Please sign in to comment.