Skip to content

Commit

Permalink
feat: non_opaque
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed Mar 6, 2024
1 parent 6582282 commit 7a625d9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions frb_codegen/src/library/codegen/parser/attribute_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ impl FrbAttributes {
self.any_eq(&FrbAttribute::Ignore)
}

pub(crate) fn opaque(&self) -> bool {
self.any_eq(&FrbAttribute::Opaque)
pub(crate) fn opaque(&self) -> Option<bool> {
if self.any_eq(&FrbAttribute::Opaque) {
Some(true)
} else if self.any_eq(&FrbAttribute::NonOpaque) {
Some(false)
} else {
None
}
}

pub(crate) fn rust_opaque_codec(&self) -> Option<RustOpaqueCodecMode> {
Expand Down Expand Up @@ -135,6 +141,7 @@ mod frb_keyword {
syn::custom_keyword!(init);
syn::custom_keyword!(ignore);
syn::custom_keyword!(opaque);
syn::custom_keyword!(non_opaque);
syn::custom_keyword!(rust_opaque_codec_moi);
syn::custom_keyword!(serialize);
syn::custom_keyword!(semi_serialize);
Expand Down Expand Up @@ -163,6 +170,7 @@ enum FrbAttribute {
Init,
Ignore,
Opaque,
NonOpaque,
RustOpaqueCodecMoi,
Serialize,
// NOTE: Undocumented, since this name may be suboptimal and is subject to change
Expand Down Expand Up @@ -201,6 +209,10 @@ impl Parse for FrbAttribute {
input
.parse::<frb_keyword::opaque>()
.map(|_| FrbAttribute::Opaque)?
} else if lookahead.peek(frb_keyword::non_opaque) {
input
.parse::<frb_keyword::non_opaque>()
.map(|_| FrbAttribute::NonOpaque)?
} else if lookahead.peek(frb_keyword::rust_opaque_codec_moi) {
input
.parse::<frb_keyword::rust_opaque_codec_moi>()
Expand Down Expand Up @@ -524,6 +536,13 @@ mod tests {
Ok(())
}

#[test]
fn test_non_opaque() -> anyhow::Result<()> {
let parsed = parse("#[frb(non_opaque)]")?;
assert_eq!(parsed, FrbAttributes(vec![FrbAttribute::NonOpaque]));
Ok(())
}

#[test]
fn test_rust_opaque_codec_moi() -> anyhow::Result<()> {
let parsed = parse("#[frb(rust_opaque_codec_moi)]")?;
Expand Down

0 comments on commit 7a625d9

Please sign in to comment.