diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-05-17 14:39:47 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-05-17 14:39:47 +0200 |
| commit | 46aace78ac4ac1c075b9b1670dbb7372df1a0a82 (patch) | |
| tree | e093f81284ffc6a5150a18bdd338da75c368120c /macros/src/util.rs | |
| parent | 42afa410ae561eb5b267080d088bca529a5d0b54 (diff) | |
Search keywords
Diffstat (limited to 'macros/src/util.rs')
| -rw-r--r-- | macros/src/util.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/macros/src/util.rs b/macros/src/util.rs index 6b683e5d..2e12ef17 100644 --- a/macros/src/util.rs +++ b/macros/src/util.rs @@ -1,4 +1,5 @@ use heck::ToKebabCase; +use quote::ToTokens; use super::*; @@ -104,13 +105,16 @@ pub fn documentation(attrs: &[syn::Attribute]) -> String { /// Extract a line of metadata from documentation. pub fn meta_line<'a>(lines: &mut Vec<&'a str>, key: &str) -> Result<&'a str> { - match lines.pop().and_then(|line| line.strip_prefix(&format!("{key}:"))) { - Some(value) => Ok(value.trim()), + match lines.last().and_then(|line| line.strip_prefix(&format!("{key}:"))) { + Some(value) => { + lines.pop(); + Ok(value.trim()) + } None => bail!(callsite, "missing metadata key: {}", key), } } -/// Creates a block responsible for building a Scope. +/// Creates a block responsible for building a `Scope`. pub fn create_scope_builder(scope_block: Option<&BlockWithReturn>) -> TokenStream { if let Some(BlockWithReturn { prefix, expr }) = scope_block { quote! { { @@ -122,3 +126,12 @@ pub fn create_scope_builder(scope_block: Option<&BlockWithReturn>) -> TokenStrea quote! { ::typst::eval::Scope::new() } } } + +/// Quotes an option literally. +pub fn quote_option<T: ToTokens>(option: &Option<T>) -> TokenStream { + if let Some(value) = option { + quote! { Some(#value) } + } else { + quote! { None } + } +} |
