Skip to content

Commit daa60cb

Browse files
committed
feat: minor tryinto
1 parent ab419ad commit daa60cb

File tree

1 file changed

+18
-0
lines changed
  • rust/catalyst-signed-doc-macro/src

1 file changed

+18
-0
lines changed

rust/catalyst-signed-doc-macro/src/field.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Structs for JSON fields.
2+
use proc_macro2::TokenStream;
3+
use quote::quote;
24

35
/// "required" field definition
46
#[derive(serde::Deserialize)]
@@ -10,6 +12,22 @@ pub(crate) enum IsRequired {
1012
Optional,
1113
}
1214

15+
impl TryInto<TokenStream> for IsRequired {
16+
type Error = anyhow::Error;
17+
18+
fn try_into(self) -> Result<TokenStream, Self::Error> {
19+
match self {
20+
Self::Yes => Ok(quote! { true }),
21+
Self::Optional => Ok(quote! { false }),
22+
Self::Excluded => {
23+
return Ok(quote! {
24+
crate::validator::rules::RefRule::NotSpecified
25+
});
26+
},
27+
}
28+
}
29+
}
30+
1331
/// Document's metadata fields definition
1432
#[derive(serde::Deserialize)]
1533
#[allow(clippy::missing_docs_in_private_items)]

0 commit comments

Comments
 (0)