Add deku_id()#176
Conversation
There was a problem hiding this comment.
Thanks @wcampbell0x2a ! Just some general comments on how to make it better. This looks great!
(Also PR is coming to fix bitvec/clippy/build errors... sorry about that)
Edit: Done. You can now rebase with master and the builds should be better
e208ec0 to
6d62a99
Compare
|
Only thing left is the |
|
Also adding docs, do you have an area in which you think docs for this function would be applicable? |
|
This make |
Here is an example: https://github.com/sharksforarms/deku/blob/master/deku-derive/src/macros/deku_read.rs#L658
Let's see what the docs look like with a |
|
Fixed generics, added to |
| let deku_id_id_type = if let Some(id_type) = id_type { | ||
| id_type | ||
| } else { | ||
| &ctx_types |
There was a problem hiding this comment.
The problem with using ctx_types is when there's more than one, it breaks:
#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
#[deku(ctx = "test: u16, my_id: u8", id = "my_id")]
enum EnumId {
#[deku(id = "1")]
VarA(u8),
#[deku(id = "2")]
VarB,
}generates
impl DekuEnumExt<'_, (u16, u8)> for EnumId {
fn deku_id(&self) -> Result<(u16, u8), DekuError> {
match self {
Self::VarA(__deku_field_0) => Ok(1),
Self::VarB => Ok(2),
_ => Err(DekuError::IdVariantNotFound),
}
}
}One way of solving this would be to find the type of input.id in input.ctx
#[deku(ctx = "test: u16, my_id: u8", id = "my_id")]
Having a utility function in macros/mod.rs would be useful. You can look at gen_ctx_types_and_arg to see how it iterates ctx
There was a problem hiding this comment.
Just pushed 3826536 with this fix. It works and the tests compile but the code quality might be lacking, any opinions or extra tests are good ;)
This creates a `deku_id()` function for enums that gives a user the ability for knowing the id of a enum variant at runtime. Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
42fbf22 to
8480ed4
Compare
Signed-off-by: wcampbell <[email protected]>
Signed-off-by: wcampbell <[email protected]>
refactor deku_id_type
sharksforarms
left a comment
There was a problem hiding this comment.
Looks great! Thanks @wcampbell0x2a
This creates a
deku_id()function for enums that gives a user the ability for knowing the id of a enum variant at runtime. See #141Any comments you have would be great! I'm still new to more advanced TokenStream fun.
DekuRead?