From 704f7c7198d2042b2a05badbe8792060d56c8f77 Mon Sep 17 00:00:00 2001 From: Pascal Sommer Date: Sat, 16 Nov 2024 20:12:56 +0100 Subject: [PATCH] fix docs: type->id_type (#494) --- deku-derive/src/macros/deku_read.rs | 2 +- deku-derive/src/macros/deku_write.rs | 2 +- src/attributes.rs | 6 +++--- src/lib.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/deku-derive/src/macros/deku_read.rs b/deku-derive/src/macros/deku_read.rs index 53788aad..54136290 100644 --- a/deku-derive/src/macros/deku_read.rs +++ b/deku-derive/src/macros/deku_read.rs @@ -363,7 +363,7 @@ fn emit_enum(input: &DekuData) -> Result { let __deku_variant_id = <#id_type>::from_reader_with_ctx(__deku_reader, (#id_args))?; } } else { - // either `id` or `type` needs to be specified + // either `id` or `id_type` needs to be specified unreachable!(); }; diff --git a/deku-derive/src/macros/deku_write.rs b/deku-derive/src/macros/deku_write.rs index cd917a36..ab32eb9b 100644 --- a/deku-derive/src/macros/deku_write.rs +++ b/deku-derive/src/macros/deku_write.rs @@ -271,7 +271,7 @@ fn emit_enum(input: &DekuData) -> Result { )); } } else { - // either `id` or `type` needs to be specified + // either `id` or `id_type` needs to be specified unreachable!(); }; diff --git a/src/attributes.rs b/src/attributes.rs index e9b6146b..a8d88cf7 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -65,7 +65,7 @@ enum DekuEnum { | enum: [id](#id) | top-level, variant | enum or variant id value | enum: [id_endian](#id_endian) | top-level | Endianness of *just* the enum `id` | enum: [id_pat](#id_pat) | variant | variant id match pattern -| enum: [type](#type) | top-level | Set the type of the variant `id` +| enum: [id_type](#id_type) | top-level | Set the type of the variant `id` | enum: [bits](#bits-1) | top-level | Set the bit-size of the variant `id` | enum: [bytes](#bytes-1) | top-level | Set the byte-size of the variant `id` @@ -1362,7 +1362,7 @@ assert_eq!(&*ret_write, data) ## id (variant) -Specify the identifier of the enum variant, must be paired with [type](#type) +Specify the identifier of the enum variant, must be paired with [id_type](#id_type) or [id (top-level)](#id-top-level) **Note**: @@ -1533,7 +1533,7 @@ let variant_bytes: Vec = value.try_into().unwrap(); assert_eq!(vec![0xFF], variant_bytes); ``` -# type +# id_type Specify the type of the enum variant id to consume, see [example](#id-variant) diff --git a/src/lib.rs b/src/lib.rs index 8a0e187c..8fceea5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -152,12 +152,12 @@ assert_eq!(DekuTest { As enums can have multiple variants, each variant must have a way to match on the incoming data. -First the "type" is read using the `type`, then is matched against the +First the "type" is read using `id_type`, then is matched against the variants given `id`. What happens after is the same as structs! This is implemented with the [id](attributes#id), [id_pat](attributes#id_pat), [default](attributes#default) and -[type](attributes#type) attributes. See these for more examples. +[id_type](attributes#id_type) attributes. See these for more examples. If no `id` is specified, the variant will default to it's discriminant value.