ferment_sys/ext/abstract/
accessory.rs1use proc_macro2::Ident;
2use quote::ToTokens;
3use syn::{parse_quote, Type};
4use syn::__private::TokenStream2;
5
6pub trait Accessory: ToTokens {
7 fn joined_mut(&self) -> Self;
8 #[allow(unused)]
9 fn joined_const(&self) -> Self;
10 #[allow(unused)]
11 fn joined_dyn(&self) -> Self;
12
13 #[allow(unused)]
14 fn joined_ref(&self) -> Self;
15
16 #[allow(unused)]
17 fn joined_mut_ref(&self) -> Self;
18 #[allow(unused)]
19 fn joined_ident(&self, ident: &Ident) -> Self;
20}
21#[macro_export]
22macro_rules! impl_accessory {
23 ($ty:ty) => {
24 impl crate::ext::Accessory for $ty {
25 fn joined_mut(&self) -> Self {
26 parse_quote!(*mut #self)
27 }
28 fn joined_const(&self) -> Self {
29 parse_quote!(*const #self)
30 }
31 fn joined_dyn(&self) -> Self {
32 parse_quote!(dyn #self)
33 }
34 fn joined_ref(&self) -> Self {
35 parse_quote!(&#self)
36 }
37 fn joined_mut_ref(&self) -> Self {
38 parse_quote!(&mut #self)
39 }
40 fn joined_ident(&self, ident: &Ident) -> Self {
41 parse_quote!(#self::#ident)
42 }
43 }
44 };
45}
46impl_accessory!(Type);
47impl_accessory!(TokenStream2);