turbo_tasks_macros_shared/
value_trait_arguments.rs

1use proc_macro2::Span;
2use syn::{
3    Meta, Token,
4    parse::{Parse, ParseStream},
5    spanned::Spanned,
6};
7
8/// Arguments to the `#[turbo_tasks::value_trait]` attribute macro.
9#[derive(Debug)]
10pub struct ValueTraitArguments {
11    /// Whether the macro should generate a `ValueDebug`-like `dbg()`
12    /// implementation on the trait's `Vc`.
13    pub debug: bool,
14    /// Should the trait have a `turbo_tasks::OperationValue` supertype?
15    pub operation: Option<Span>,
16}
17
18impl Default for ValueTraitArguments {
19    fn default() -> Self {
20        Self {
21            debug: true,
22            operation: None,
23        }
24    }
25}
26
27impl Parse for ValueTraitArguments {
28    fn parse(input: ParseStream) -> syn::Result<Self> {
29        let mut result = Self::default();
30        if input.is_empty() {
31            return Ok(result);
32        }
33
34        let punctuated = input.parse_terminated(Meta::parse, Token![,])?;
35        for meta in punctuated {
36            match meta.path().get_ident().map(ToString::to_string).as_deref() {
37                Some("no_debug") => {
38                    result.debug = false;
39                }
40                Some("operation") => {
41                    result.operation = Some(meta.span());
42                }
43                _ => {
44                    return Err(syn::Error::new_spanned(meta, "unknown parameter"));
45                }
46            }
47        }
48
49        Ok(result)
50    }
51}