1 | use proc_macro2::TokenStream; |
---|---|
2 | use quote::ToTokens; |
3 | |
4 | pub(crate) struct TokensOrDefault<'a, T: 'a>(pub &'a Option<T>); |
5 | |
6 | impl<'a, T> ToTokens for TokensOrDefault<'a, T> |
7 | where |
8 | T: ToTokens + Default, |
9 | { |
10 | fn to_tokens(&self, tokens: &mut TokenStream) { |
11 | match self.0 { |
12 | Some(t) => t.to_tokens(tokens), |
13 | None => T::default().to_tokens(tokens), |
14 | } |
15 | } |
16 | } |
17 |