derive_builder_core_fork_arti/
default_expression.rs1use crate::BlockContents;
2use quote::{ToTokens, TokenStreamExt};
3
4#[derive(Debug, Clone)]
6pub enum DefaultExpression {
7 Explicit(BlockContents),
8 Trait,
9}
10
11impl DefaultExpression {
12 #[cfg(test)]
13 pub fn explicit<I: Into<BlockContents>>(content: I) -> Self {
14 DefaultExpression::Explicit(content.into())
15 }
16}
17
18impl darling::FromMeta for DefaultExpression {
19 fn from_word() -> darling::Result<Self> {
20 Ok(DefaultExpression::Trait)
21 }
22
23 fn from_value(value: &syn::Lit) -> darling::Result<Self> {
24 Ok(Self::Explicit(BlockContents::from_value(value)?))
25 }
26}
27
28impl ToTokens for DefaultExpression {
29 fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
30 match *self {
31 Self::Explicit(ref block) => block.to_tokens(tokens),
32 Self::Trait => tokens.append_all(quote!(
33 ::derive_builder::export::core::default::Default::default()
34 )),
35 }
36 }
37}