Skip to content

Commit

Permalink
feat: attr
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed Jun 7, 2024
1 parent 7f7c50b commit 33dea56
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions frb_codegen/src/library/codegen/parser/mir/parser/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ impl FrbAttributes {
self.any_eq(&FrbAttribute::External)
}

pub(crate) fn generate_impl_enum(&self) -> bool {
self.any_eq(&FrbAttribute::GenerateImplEnum)
}

pub(crate) fn rust_opaque_codec(&self) -> Option<RustOpaqueCodecMode> {
if self.any_eq(&FrbAttribute::RustOpaqueCodecMoi) {
Some(RustOpaqueCodecMode::Moi)
Expand Down Expand Up @@ -191,6 +195,7 @@ mod frb_keyword {
syn::custom_keyword!(non_eq);
syn::custom_keyword!(positional);
syn::custom_keyword!(external);
syn::custom_keyword!(generate_impl_enum);
syn::custom_keyword!(rust_opaque_codec_moi);
syn::custom_keyword!(serialize);
syn::custom_keyword!(semi_serialize);
Expand Down Expand Up @@ -229,6 +234,7 @@ enum FrbAttribute {
NonEq,
Positional,
External,
GenerateImplEnum,
RustOpaqueCodecMoi,
Serialize,
// NOTE: Undocumented, since this name may be suboptimal and is subject to change
Expand Down Expand Up @@ -266,6 +272,14 @@ impl Parse for FrbAttribute {
.or_else(|| parse_keyword::<non_eq, _>(input, &lookahead, non_eq, NonEq))
.or_else(|| parse_keyword::<positional, _>(input, &lookahead, positional, Positional))
.or_else(|| parse_keyword::<external, _>(input, &lookahead, external, External))
.or_else(|| {
parse_keyword::<generate_impl_enum, _>(
input,
&lookahead,
generate_impl_enum,
GenerateImplEnum,
)
})
.or_else(|| {
parse_keyword::<rust_opaque_codec_moi, _>(
input,
Expand Down Expand Up @@ -661,6 +675,11 @@ mod tests {
simple_keyword_tester("external", FrbAttribute::External);
}

#[test]
fn test_generate_impl_enum() {
simple_keyword_tester("generate_impl_enum", FrbAttribute::GenerateImplEnum);
}

#[test]
fn test_rust_opaque_codec_moi() {
simple_keyword_tester("rust_opaque_codec_moi", FrbAttribute::RustOpaqueCodecMoi);
Expand Down

0 comments on commit 33dea56

Please sign in to comment.