-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial derive(Encode, RefEncode) implementation
- Loading branch information
Showing
4 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use syn::{Attribute, Ident, Meta, NestedMeta}; | ||
|
||
// Taken from `nom-derive`: | ||
// https://github.com/rust-bakery/nom-derive/blob/5315891a0016b15094d4d0201f7d3ac803e4fc57/nom-derive-impl/src/enums.rs#L60-L90 | ||
pub(crate) fn get_repr(attrs: &[Attribute]) -> Option<Ident> { | ||
for attr in attrs { | ||
if let Ok(Meta::List(metalist)) = attr.parse_meta() { | ||
if let Some(ident) = metalist.path.get_ident() { | ||
if ident == "repr" { | ||
for n in metalist.nested.iter() { | ||
match n { | ||
NestedMeta::Meta(meta) => match meta { | ||
Meta::Path(path) => { | ||
if let Some(word) = path.get_ident() { | ||
return Some(word.clone()); | ||
} else { | ||
panic!("unsupported nested type for 'repr'") | ||
} | ||
} | ||
_ => panic!("unsupported nested type for 'repr'"), | ||
}, | ||
_ => panic!("unsupported meta type for 'repr'"), | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
None | ||
} |