Repository: sharksforarms/deku
Pull request #95 (2020-09-02 23:44:37)

Deprecate `id_bits` in favor of `bits`
- More direct change, with a full change of all mentions of `id_bits`
  to `bits`.

See #89

codecov[bot]: # [Codecov](https://codecov.io/gh/sharksforarms/deku/pull/95?src=pr&el=h1) Report
> Merging [#95](https://codecov.io/gh/sharksforarms/deku/pull/95?src=pr&el=desc) into [master](https://codecov.io/gh/sharksforarms/deku/commit/d2a00b1dd59796a18611ed0a891e89aa656c6bb4?el=desc) will **not change** coverage.
> The diff coverage is `80.00%`.

[![Impacted file tree graph](https://codecov.io/gh/sharksforarms/deku/pull/95/graphs/tree.svg?width=650&height=150&src=pr&token=MFMETW02MZ)](https://codecov.io/gh/sharksforarms/deku/pull/95?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master      #95   +/-   ##
=======================================
  Coverage   51.64%   51.64%           
=======================================
  Files          15       15           
  Lines        3247     3247           
=======================================
  Hits         1677     1677           
  Misses       1570     1570           
```


| [Impacted Files](https://codecov.io/gh/sharksforarms/deku/pull/95?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [deku-derive/src/macros/mod.rs](https://codecov.io/gh/sharksforarms/deku/pull/95/diff?src=pr&el=tree#diff-ZGVrdS1kZXJpdmUvc3JjL21hY3Jvcy9tb2QucnM=) | `96.59% <ø> (ø)` | |
| [tests/test\_from\_bytes.rs](https://codecov.io/gh/sharksforarms/deku/pull/95/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9mcm9tX2J5dGVzLnJz) | `94.73% <ø> (ø)` | |
| [deku-derive/src/lib.rs](https://codecov.io/gh/sharksforarms/deku/pull/95/diff?src=pr&el=tree#diff-ZGVrdS1kZXJpdmUvc3JjL2xpYi5ycw==) | `75.94% <75.00%> (ø)` | |
| [deku-derive/src/macros/deku\_read.rs](https://codecov.io/gh/sharksforarms/deku/pull/95/diff?src=pr&el=tree#diff-ZGVrdS1kZXJpdmUvc3JjL21hY3Jvcy9kZWt1X3JlYWQucnM=) | `98.46% <100.00%> (ø)` | |
| [deku-derive/src/macros/deku\_write.rs](https://codecov.io/gh/sharksforarms/deku/pull/95/diff?src=pr&el=tree#diff-ZGVrdS1kZXJpdmUvc3JjL21hY3Jvcy9kZWt1X3dyaXRlLnJz) | `98.44% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/sharksforarms/deku/pull/95?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/sharksforarms/deku/pull/95?src=pr&el=footer). Last update [d2a00b1...ed86655](https://codecov.io/gh/sharksforarms/deku/pull/95?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6e47b52..f72b375 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
 # Changelog
 
 ## [Unreleased]
+- Deprecated `id_bits` in favor of `bits`
 
 ## [0.7.1] - 2020-09-02
 
diff --git a/deku-derive/src/lib.rs b/deku-derive/src/lib.rs
index 22cdea6..95f35cf 100644
--- a/deku-derive/src/lib.rs
+++ b/deku-derive/src/lib.rs
@@ -30,8 +30,8 @@ struct DekuData {
     id_type: Option<syn::Ident>,
 
     /// enum only: bit size of the enum `id`
-    /// `id_bytes` is converted to `id_bits` if provided
-    id_bits: Option<usize>,
+    /// `id_bytes` is converted to `bits` if provided
+    bits: Option<usize>,
 }
 
 impl DekuData {
@@ -71,7 +71,7 @@ impl DekuData {
             .transpose()
             .map_err(|e| e.to_compile_error())?;
 
-        let id_bits = receiver.id_bytes.map(|b| b * 8).or(receiver.id_bits);
+        let bits = receiver.id_bytes.map(|b| b * 8).or(receiver.bits);
 
         Ok(Self {
             vis: receiver.vis,
@@ -83,7 +83,7 @@ impl DekuData {
             ctx_default,
             id: receiver.id,
             id_type: receiver.id_type,
-            id_bits,
+            bits,
         })
     }
 
@@ -112,8 +112,8 @@ impl DekuData {
                         receiver.id_bytes.span(),
                         "`id_bytes` only supported on enum",
                     ))
-                } else if receiver.id_bits.is_some() {
-                    Err((receiver.id_bits.span(), "`id_bits` only supported on enum"))
+                } else if receiver.bits.is_some() {
+                    Err((receiver.bits.span(), "`bits` only supported on enum"))
                 } else {
                     Ok(())
                 }
@@ -136,11 +136,8 @@ impl DekuData {
                 }
 
                 // Validate `id_*` used correctly
-                if receiver.id.is_some() && receiver.id_bits.is_some() {
-                    return Err((
-                        receiver.ident.span(),
-                        "error: cannot use `id_bits` with `id`",
-                    ));
+                if receiver.id.is_some() && receiver.bits.is_some() {
+                    return Err((receiver.ident.span(), "error: cannot use `bits` with `id`"));
                 }
                 if receiver.id.is_some() && receiver.id_bytes.is_some() {
                     return Err((
@@ -149,11 +146,11 @@ impl DekuData {
                     ));
                 }
 
-                // Validate either `id_bits` or `id_bytes` is specified
-                if receiver.id_bits.is_some() && receiver.id_bytes.is_some() {
+                // Validate either `bits` or `id_bytes` is specified
+                if receiver.bits.is_some() && receiver.id_bytes.is_some() {
                     return Err((
-                        receiver.id_bits.span(),
-                        "conflicting: both `id_bits` and `id_bytes` specified on enum",
+                        receiver.bits.span(),
+                        "conflicting: both `bits` and `id_bytes` specified on enum",
                     ));
                 }
 
@@ -399,7 +396,7 @@ struct DekuReceiver {
 
     /// enum only: bit size of the enum `id`
     #[darling(default)]
-    id_bits: Option<usize>,
+    bits: Option<usize>,
 
     /// enum only: byte size of the enum `id`
     #[darling(default)]
diff --git a/deku-derive/src/macros/deku_read.rs b/deku-derive/src/macros/deku_read.rs
index e940273..d95498a 100644
--- a/deku-derive/src/macros/deku_read.rs
+++ b/deku-derive/src/macros/deku_read.rs
@@ -132,7 +132,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
     let id = input.id.as_ref();
     let id_type = input.id_type.as_ref();
 
-    let id_args = gen_id_args(input.endian.as_ref(), input.id_bits)?;
+    let id_args = gen_id_args(input.endian.as_ref(), input.bits)?;
 
     let mut variant_matches = vec![];
     let mut has_default_match = false;
diff --git a/deku-derive/src/macros/deku_write.rs b/deku-derive/src/macros/deku_write.rs
index e5ec823..dc0457f 100644
--- a/deku-derive/src/macros/deku_write.rs
+++ b/deku-derive/src/macros/deku_write.rs
@@ -147,7 +147,7 @@ fn emit_enum(input: &DekuData) -> Result<TokenStream, syn::Error> {
     let id = input.id.as_ref();
     let id_type = input.id_type.as_ref();
 
-    let id_args = gen_id_args(input.endian.as_ref(), input.id_bits)?;
+    let id_args = gen_id_args(input.endian.as_ref(), input.bits)?;
 
     let mut variant_writes = vec![];
     let mut variant_updates = vec![];
diff --git a/deku-derive/src/macros/mod.rs b/deku-derive/src/macros/mod.rs
index e730e66..43009eb 100644
--- a/deku-derive/src/macros/mod.rs
+++ b/deku-derive/src/macros/mod.rs
@@ -160,7 +160,7 @@ fn gen_ctx_types_and_arg(
 }
 
 /// Generate argument for `id`:
-/// `#deku(endian = "big", id_bits = "1")` -> `Endian::Big, BitSize(1)`
+/// `#deku(endian = "big", bits = "1")` -> `Endian::Big, BitSize(1)`
 fn gen_id_args(endian: Option<&syn::LitStr>, bits: Option<usize>) -> syn::Result<TokenStream> {
     let endian = endian.map(gen_endian_from_str).transpose()?;
     let bits = bits.map(|n| quote! {deku::ctx::BitSize(#n)});
@@ -179,7 +179,7 @@ fn gen_id_args(endian: Option<&syn::LitStr>, bits: Option<usize>) -> syn::Result
 
 /// Generate argument for fields:
 ///
-/// `#deku(endian = "big", id_bits = "1", ctx = "a")` -> `Endian::Big, BitSize(1), a`
+/// `#deku(endian = "big", bits = "1", ctx = "a")` -> `Endian::Big, BitSize(1), a`
 fn gen_field_args(
     endian: Option<&syn::LitStr>,
     bits: Option<usize>,
diff --git a/src/attributes.rs b/src/attributes.rs
index b176695..e13b02f 100644
--- a/src/attributes.rs
+++ b/src/attributes.rs
@@ -21,7 +21,7 @@ A documentation-only module for #[deku] attributes
 | enum: [id](#id) | top-level, variant | enum or variant id value
 | enum: [id_pat](#id_pat) | variant | variant id match pattern
 | enum: [id_type](#id_type) | top-level | Set the type of the variant `id`
-| enum: [id_bits](#id_bits) | top-level | Set the bit-size of the variant `id`
+| enum: [bits](#bits) | top-level | Set the bit-size of the variant `id`
 | enum: [id_bytes](#id_bytes) | top-level | Set the byte-size of the variant `id`
 
 # endian
@@ -680,7 +680,7 @@ assert_eq!(data, variant_bytes);
 
 Specify the type of the enum variant id to consume, see [example](#id-variant)
 
-# id_bits
+# bits
 
 Set the bit size of the enum variant `id`
 
@@ -691,7 +691,7 @@ Example:
 # use deku::prelude::*;
 # use std::convert::{TryInto, TryFrom};
 # #[derive(PartialEq, Debug, DekuRead, DekuWrite)]
-#[deku(id_type = "u8", id_bits = "4")]
+#[deku(id_type = "u8", bits = "4")]
 enum DekuTest {
     #[deku(id = "0b1001")]
     VariantA( #[deku(bits = "4")] u8, u8),
@@ -714,7 +714,7 @@ assert_eq!(data, value);
 
 Set the byte size of the enum variant `id`
 
-**Note**: Cannot be used in combination with [id_bits](#id_bits)
+**Note**: Cannot be used in combination with [bits](#bits)
 
 Example:
 ```rust


Test patch:
diff --git a/tests/macro_read/bits_bytes_conflict.rs b/tests/macro_read/bits_bytes_conflict.rs
index c1ed406..4237d94 100644
--- a/tests/macro_read/bits_bytes_conflict.rs
+++ b/tests/macro_read/bits_bytes_conflict.rs
@@ -1,7 +1,7 @@
 use deku::prelude::*;
 
 #[derive(DekuRead)]
-#[deku(id_type = "u8", id_bits = "1", id_bytes = "2")]
+#[deku(id_type = "u8", bits = "1", id_bytes = "2")]
 enum Test1 {}
 
 #[derive(DekuRead)]
diff --git a/tests/macro_read/bits_bytes_conflict.stderr b/tests/macro_read/bits_bytes_conflict.stderr
index ca5651e..d43805a 100644
--- a/tests/macro_read/bits_bytes_conflict.stderr
+++ b/tests/macro_read/bits_bytes_conflict.stderr
@@ -1,4 +1,4 @@
-error: conflicting: both `id_bits` and `id_bytes` specified on enum
+error: conflicting: both `bits` and `id_bytes` specified on enum
  --> $DIR/bits_bytes_conflict.rs:3:10
   |
 3 | #[derive(DekuRead)]
diff --git a/tests/macro_read/enum_validation.rs b/tests/macro_read/enum_validation.rs
index 6a6aa39..848a00e 100644
--- a/tests/macro_read/enum_validation.rs
+++ b/tests/macro_read/enum_validation.rs
@@ -23,16 +23,16 @@ struct Test4 {
     a: u8
 }
 
-// test `id_bits` only allowed on enum
+// test `bits` only allowed on enum
 #[derive(DekuRead)]
-#[deku(id_bits = "1")]
+#[deku(bits = "1")]
 struct Test5 {
     a: u8
 }
 
 // test `id_bytes` only allowed on enum
 #[derive(DekuRead)]
-#[deku(id_bits = "1")]
+#[deku(bits = "1")]
 struct Test6 {
     a: u8
 }
@@ -44,9 +44,9 @@ struct Test7 {
     a: u8
 }
 
-// test `id_bits` cannot be used with `id`
+// test `bits` cannot be used with `id`
 #[derive(DekuRead)]
-#[deku(id = "test", id_bits = "4")]
+#[deku(id = "test", bits = "4")]
 enum Test8 {
     A
 }
diff --git a/tests/macro_read/enum_validation.stderr b/tests/macro_read/enum_validation.stderr
index c955768..8a1f82c 100644
--- a/tests/macro_read/enum_validation.stderr
+++ b/tests/macro_read/enum_validation.stderr
@@ -22,7 +22,7 @@ error: `id_type` only supported on enum
 21 | #[deku(id_type = "u8")]
    |                  ^^^^
 
-error: `id_bits` only supported on enum
+error: `bits` only supported on enum
   --> $DIR/enum_validation.rs:27:10
    |
 27 | #[derive(DekuRead)]
@@ -30,7 +30,7 @@ error: `id_bits` only supported on enum
    |
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: `id_bits` only supported on enum
+error: `bits` only supported on enum
   --> $DIR/enum_validation.rs:34:10
    |
 34 | #[derive(DekuRead)]
@@ -44,7 +44,7 @@ error: `id` only supported on enum
 42 | #[deku(id = "test")]
    |             ^^^^^^
 
-error: error: cannot use `id_bits` with `id`
+error: error: cannot use `bits` with `id`
   --> $DIR/enum_validation.rs:50:6
    |
 50 | enum Test8 {
diff --git a/tests/test_from_bytes.rs b/tests/test_from_bytes.rs
index 9c25af6..babd8cc 100644
--- a/tests/test_from_bytes.rs
+++ b/tests/test_from_bytes.rs
@@ -31,7 +31,7 @@ fn test_from_bytes_struct() {
 #[test]
 fn test_from_bytes_enum() {
     #[derive(Debug, PartialEq, DekuRead, DekuWrite)]
-    #[deku(id_type = "u8", id_bits = "4")]
+    #[deku(id_type = "u8", bits = "4")]
     enum TestDeku {
         #[deku(id = "0b0110")]
         VariantA(#[deku(bits = "4")] u8),