Skip to main content

zvariant_utils/derive/
mod.rs

1//! Code generation shared by the `zvariant_derive` and `zgvariant_derive` proc-macro crates.
2
3use proc_macro2::TokenStream;
4use quote::quote;
5
6pub mod attrs;
7pub use attrs::*;
8
9mod dict;
10pub use dict::{expand_deserialize_dict_derive, expand_serialize_dict_derive};
11
12mod signature;
13pub use signature::*;
14
15mod r#type;
16pub use r#type::expand_type_derive;
17
18mod value;
19pub use value::{ValueType, expand_value_derive};
20
21/// Configuration for a derive crate using this code generation.
22pub struct Config {
23    /// Attribute list names to parse, e.g. `["zvariant", "zbus"]`.
24    pub attr_lists: &'static [&'static str],
25    /// Crate path used when the user doesn't override it via the `crate` attribute.
26    pub default_path: TokenStream,
27}
28
29impl Config {
30    /// The crate path to emit, honoring the user's `crate` attribute override.
31    pub fn resolve_path(&self, crate_attr: Option<&str>) -> syn::Result<TokenStream> {
32        Ok(match attrs::parse_crate_path(crate_attr)? {
33            Some(path) => quote! { ::#path },
34            None => self.default_path.clone(),
35        })
36    }
37}