Skip to content

Commit

Permalink
Generate non bitfield enums
Browse files Browse the repository at this point in the history
  • Loading branch information
morr0ne committed Aug 14, 2024
1 parent c29e237 commit 8609f0c
Show file tree
Hide file tree
Showing 2 changed files with 1,747 additions and 2 deletions.
23 changes: 23 additions & 0 deletions gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,29 @@ fn write_enums(interface: &Interface) -> Vec<TokenStream> {
let name = make_ident(e.name.to_upper_camel_case());

if !e.bitfield {
let mut variants = Vec::new();

variants.push(quote! { Temp });

enums.push(quote! {
#[repr(u32)]
#[non_exhaustive]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
pub enum #name {
#(#variants),*
}

impl TryFrom<u32> for #name {
type Error = crate::wire::DecodeError;

fn try_from(v: u32) -> Result<Self, Self::Error> {
match v {
// {match_variants}
_ => Err(crate::wire::DecodeError::MalformedPayload)
}
}
}
})
} else {
let mut variants = Vec::new();

Expand Down
Loading

0 comments on commit 8609f0c

Please sign in to comment.