Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to bitvec 1.0.0 #281

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -22,7 +22,7 @@ jobs:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -37,7 +37,7 @@ jobs:
name: Miri Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
Expand All @@ -49,7 +49,7 @@ jobs:
name: Miri Test Big Endian
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
Expand All @@ -62,7 +62,7 @@ jobs:
name: Examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -74,7 +74,7 @@ jobs:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -90,7 +90,7 @@ jobs:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -106,7 +106,7 @@ jobs:
name: Ensure no_std
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
Expand All @@ -117,7 +117,7 @@ jobs:
name: Ensure wasm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
Expand All @@ -135,7 +135,7 @@ jobs:
options: --security-opt seccomp=unconfined
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Generate code coverage
run: |
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ jobs:
name: Benchmark
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: jasonwilliams/criterion-compare-action@move_to_actions
- uses: boa-dev/criterion-compare-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branchName: ${{ github.base_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ const_generics = []

[dependencies]
deku_derive = { version = "^0.14.0", path = "deku-derive", default-features = false}
bitvec = { version = "0.22.1", default-features = false }
bitvec = { version = "1.0.1", default-features = false }
log = { version = "0.4.17", optional = true }

[dev-dependencies]
rstest = "0.13.0"
hexlit = "0.5.3"
criterion = "0.3.5"
rstest = "0.15.0"
hexlit = "0.5.5"
criterion = "0.4.0"
alloc_counter = "0.0.4"
trybuild = "1.0.54"
trybuild = "1.0.71"
rustc-hash = "1.1.0"
env_logger = "0.9.1"
env_logger = "0.9.3"

[[bench]]
name = "deku"
Expand Down
14 changes: 7 additions & 7 deletions deku-derive/src/macros/deku_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
let __deku_pad = 8 * ((__deku_rest.len() + 7) / 8) - __deku_rest.len();
let __deku_read_idx = __deku_input_bits.len() - (__deku_rest.len() + __deku_pad);

Ok(((__deku_input_bits[__deku_read_idx..].as_raw_slice(), __deku_pad), __deku_value))
Ok(((__deku_input_bits[__deku_read_idx..].domain().region().unwrap().1, __deku_pad), __deku_value))
},
&input.ctx,
&input.ctx_default,
Expand Down Expand Up @@ -110,7 +110,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {

tokens.extend(quote! {
impl #imp ::#crate_::DekuRead<#lifetime, #ctx_types> for #ident #wher {
fn read(__deku_input_bits: &#lifetime ::#crate_::bitvec::BitSlice<::#crate_::bitvec::Msb0, u8>, #ctx_arg) -> Result<(&#lifetime ::#crate_::bitvec::BitSlice<::#crate_::bitvec::Msb0, u8>, Self), ::#crate_::DekuError> {
fn read(__deku_input_bits: &#lifetime ::#crate_::bitvec::BitSlice<u8, ::#crate_::bitvec::Msb0>, #ctx_arg) -> Result<(&#lifetime ::#crate_::bitvec::BitSlice<u8, ::#crate_::bitvec::Msb0>, Self), ::#crate_::DekuError> {
#read_body
}
}
Expand All @@ -121,7 +121,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {

tokens.extend(quote! {
impl #imp ::#crate_::DekuRead<#lifetime> for #ident #wher {
fn read(__deku_input_bits: &#lifetime ::#crate_::bitvec::BitSlice<::#crate_::bitvec::Msb0, u8>, _: ()) -> Result<(&#lifetime ::#crate_::bitvec::BitSlice<::#crate_::bitvec::Msb0, u8>, Self), ::#crate_::DekuError> {
fn read(__deku_input_bits: &#lifetime ::#crate_::bitvec::BitSlice<u8, ::#crate_::bitvec::Msb0>, _: ()) -> Result<(&#lifetime ::#crate_::bitvec::BitSlice<u8, ::#crate_::bitvec::Msb0>, Self), ::#crate_::DekuError> {
#read_body
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
let __deku_pad = 8 * ((__deku_rest.len() + 7) / 8) - __deku_rest.len();
let __deku_read_idx = __deku_input_bits.len() - (__deku_rest.len() + __deku_pad);

Ok(((__deku_input_bits[__deku_read_idx..].as_raw_slice(), __deku_pad), __deku_value))
Ok(((__deku_input_bits[__deku_read_idx..].domain().region().unwrap().1, __deku_pad), __deku_value))
},
&input.ctx,
&input.ctx_default,
Expand Down Expand Up @@ -340,7 +340,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
tokens.extend(quote! {
#[allow(non_snake_case)]
impl #imp ::#crate_::DekuRead<#lifetime, #ctx_types> for #ident #wher {
fn read(__deku_input_bits: &#lifetime ::#crate_::bitvec::BitSlice<::#crate_::bitvec::Msb0, u8>, #ctx_arg) -> Result<(&#lifetime ::#crate_::bitvec::BitSlice<::#crate_::bitvec::Msb0, u8>, Self), ::#crate_::DekuError> {
fn read(__deku_input_bits: &#lifetime ::#crate_::bitvec::BitSlice<u8, ::#crate_::bitvec::Msb0>, #ctx_arg) -> Result<(&#lifetime ::#crate_::bitvec::BitSlice<u8, ::#crate_::bitvec::Msb0>, Self), ::#crate_::DekuError> {
#read_body
}
}
Expand All @@ -352,7 +352,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
tokens.extend(quote! {
#[allow(non_snake_case)]
impl #imp ::#crate_::DekuRead<#lifetime> for #ident #wher {
fn read(__deku_input_bits: &#lifetime ::#crate_::bitvec::BitSlice<::#crate_::bitvec::Msb0, u8>, _: ()) -> Result<(&#lifetime ::#crate_::bitvec::BitSlice<::#crate_::bitvec::Msb0, u8>, Self), ::#crate_::DekuError> {
fn read(__deku_input_bits: &#lifetime ::#crate_::bitvec::BitSlice<u8, ::#crate_::bitvec::Msb0>, _: ()) -> Result<(&#lifetime ::#crate_::bitvec::BitSlice<u8, ::#crate_::bitvec::Msb0>, Self), ::#crate_::DekuError> {
#read_body
}
}
Expand Down Expand Up @@ -453,7 +453,7 @@ fn emit_bit_byte_offsets(
|| byte_offset.is_some()
{
Some(quote! {
let __deku_bit_offset = usize::try_from(__deku_input_bits.offset_from(__deku_rest))?;
let __deku_bit_offset = usize::try_from(unsafe { __deku_rest.as_bitptr().offset_from(__deku_input_bits.as_bitptr()) } )?;
})
} else {
None
Expand Down
24 changes: 12 additions & 12 deletions deku-derive/src/macros/deku_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
quote! {
match *self {
#destructured => {
let mut __deku_acc: ::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8> = ::#crate_::bitvec::BitVec::new();
let mut __deku_acc: ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0> = ::#crate_::bitvec::BitVec::new();
let __deku_output = &mut __deku_acc;

#magic_write
Expand All @@ -62,7 +62,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
);

tokens.extend(quote! {
impl #imp core::convert::TryFrom<#ident> for ::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8> #wher {
impl #imp core::convert::TryFrom<#ident> for ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0> #wher {
type Error = ::#crate_::DekuError;

fn try_from(input: #ident) -> Result<Self, Self::Error> {
Expand All @@ -80,12 +80,12 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {

impl #imp DekuContainerWrite for #ident #wher {
fn to_bytes(&self) -> Result<Vec<u8>, ::#crate_::DekuError> {
let mut acc: ::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8> = self.to_bits()?;
let mut acc: ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0> = self.to_bits()?;
Ok(acc.into_vec())
}

#[allow(unused_variables)]
fn to_bits(&self) -> Result<::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8>, ::#crate_::DekuError> {
fn to_bits(&self) -> Result<::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0>, ::#crate_::DekuError> {
#to_bits_body
}
}
Expand Down Expand Up @@ -120,7 +120,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {

impl #imp DekuWrite<#ctx_types> for #ident #wher {
#[allow(unused_variables)]
fn write(&self, __deku_output: &mut ::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8>, #ctx_arg) -> Result<(), ::#crate_::DekuError> {
fn write(&self, __deku_output: &mut ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0>, #ctx_arg) -> Result<(), ::#crate_::DekuError> {
#write_body
}
}
Expand All @@ -132,7 +132,7 @@ fn emit_struct(input: &DekuData) -> Result<TokenStream, syn::Error> {
tokens.extend(quote! {
impl #imp DekuWrite for #ident #wher {
#[allow(unused_variables)]
fn write(&self, __deku_output: &mut ::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8>, _: ()) -> Result<(), ::#crate_::DekuError> {
fn write(&self, __deku_output: &mut ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0>, _: ()) -> Result<(), ::#crate_::DekuError> {
#write_body
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
if input.ctx.is_none() || (input.ctx.is_some() && input.ctx_default.is_some()) {
let to_bits_body = wrap_default_ctx(
quote! {
let mut __deku_acc: ::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8> = ::#crate_::bitvec::BitVec::new();
let mut __deku_acc: ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0> = ::#crate_::bitvec::BitVec::new();
let __deku_output = &mut __deku_acc;

#magic_write
Expand All @@ -274,7 +274,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
);

tokens.extend(quote! {
impl #imp core::convert::TryFrom<#ident> for ::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8> #wher {
impl #imp core::convert::TryFrom<#ident> for ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0> #wher {
type Error = ::#crate_::DekuError;

fn try_from(input: #ident) -> Result<Self, Self::Error> {
Expand All @@ -292,12 +292,12 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {

impl #imp DekuContainerWrite for #ident #wher {
fn to_bytes(&self) -> Result<Vec<u8>, ::#crate_::DekuError> {
let mut acc: ::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8> = self.to_bits()?;
let mut acc: ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0> = self.to_bits()?;
Ok(acc.into_vec())
}

#[allow(unused_variables)]
fn to_bits(&self) -> Result<::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8>, ::#crate_::DekuError> {
fn to_bits(&self) -> Result<::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0>, ::#crate_::DekuError> {
#to_bits_body
}
}
Expand Down Expand Up @@ -334,7 +334,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {

impl #imp DekuWrite<#ctx_types> for #ident #wher {
#[allow(unused_variables)]
fn write(&self, __deku_output: &mut ::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8>, #ctx_arg) -> Result<(), ::#crate_::DekuError> {
fn write(&self, __deku_output: &mut ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0>, #ctx_arg) -> Result<(), ::#crate_::DekuError> {
#write_body
}
}
Expand All @@ -346,7 +346,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
tokens.extend(quote! {
impl #imp DekuWrite for #ident #wher {
#[allow(unused_variables)]
fn write(&self, __deku_output: &mut ::#crate_::bitvec::BitVec<::#crate_::bitvec::Msb0, u8>, _: ()) -> Result<(), ::#crate_::DekuError> {
fn write(&self, __deku_output: &mut ::#crate_::bitvec::BitVec<u8, ::#crate_::bitvec::Msb0>, _: ()) -> Result<(), ::#crate_::DekuError> {
#write_body
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/custom_reader_and_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::convert::TryInto;

fn bit_flipper_read(
field_a: u8,
rest: &BitSlice<Msb0, u8>,
rest: &BitSlice<u8, Msb0>,
bit_size: BitSize,
) -> Result<(&BitSlice<Msb0, u8>, u8), DekuError> {
) -> Result<(&BitSlice<u8, Msb0>, u8), DekuError> {
// Access to previously read fields
println!("field_a = 0x{:X}", field_a);

Expand All @@ -29,7 +29,7 @@ fn bit_flipper_read(
fn bit_flipper_write(
field_a: u8,
field_b: u8,
output: &mut BitVec<Msb0, u8>,
output: &mut BitVec<u8, Msb0>,
bit_size: BitSize,
) -> Result<(), DekuError> {
// Access to previously written fields
Expand Down
6 changes: 3 additions & 3 deletions src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,14 +776,14 @@ struct DekuTest {
impl DekuTest {
/// Read and convert to String
fn read(
rest: &BitSlice<Msb0, u8>,
) -> Result<(&BitSlice<Msb0, u8>, String), DekuError> {
rest: &BitSlice<u8, Msb0>,
) -> Result<(&BitSlice<u8, Msb0>, String), DekuError> {
let (rest, value) = u8::read(rest, ())?;
Ok((rest, value.to_string()))
}

/// Parse from String to u8 and write
fn write(output: &mut BitVec<Msb0, u8>, field_a: &str) -> Result<(), DekuError> {
fn write(output: &mut BitVec<u8, Msb0>, field_a: &str) -> Result<(), DekuError> {
let value = field_a.parse::<u8>().unwrap();
value.write(output, ())
}
Expand Down
10 changes: 5 additions & 5 deletions src/impls/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ where
/// wrapper around u8::read with consideration to context, such as bit size
/// true if the result of the read is `1`, false if `0` and error otherwise
fn read(
input: &'a BitSlice<Msb0, u8>,
input: &'a BitSlice<u8, Msb0>,
inner_ctx: Ctx,
) -> Result<(&'a BitSlice<Msb0, u8>, Self), DekuError> {
) -> Result<(&'a BitSlice<u8, Msb0>, Self), DekuError> {
let (rest, val) = u8::read(input, inner_ctx)?;

let ret = match val {
Expand All @@ -35,7 +35,7 @@ where
u8: DekuWrite<Ctx>,
{
/// wrapper around u8::write with consideration to context, such as bit size
fn write(&self, output: &mut BitVec<Msb0, u8>, inner_ctx: Ctx) -> Result<(), DekuError> {
fn write(&self, output: &mut BitVec<u8, Msb0>, inner_ctx: Ctx) -> Result<(), DekuError> {
match self {
true => (0x01u8).write(output, inner_ctx),
false => (0x00u8).write(output, inner_ctx),
Expand All @@ -62,7 +62,7 @@ mod tests {
assert_eq!(expected, res_read);
assert!(rest.is_empty());

let mut res_write = bitvec![Msb0, u8;];
let mut res_write = bitvec![u8, Msb0;];
res_read.write(&mut res_write, ()).unwrap();
assert_eq!(input.to_vec(), res_write.into_vec());
}
Expand All @@ -76,7 +76,7 @@ mod tests {
assert_eq!(true, res_read);
assert_eq!(6, rest.len());

let mut res_write = bitvec![Msb0, u8;];
let mut res_write = bitvec![u8, Msb0;];
res_read.write(&mut res_write, ()).unwrap();
assert_eq!(vec![0b01], res_write.into_vec());
}
Expand Down
Loading