Skip to content

Commit 070ae73

Browse files
committed
doc
1 parent 1620e17 commit 070ae73

File tree

1 file changed

+96
-0
lines changed
  • src/common/base/macros/src

1 file changed

+96
-0
lines changed

src/common/base/macros/src/lib.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,36 @@ use syn::Type;
1313
use syn::parse_macro_input;
1414
use syn::parse_quote;
1515

16+
/// Derives `::databend_common_base::base::Service` for a struct or enum.
17+
///
18+
/// Supported forms:
19+
/// - `#[derive(Service)]` on a struct or enum uses the default symbol
20+
/// `<TypeName>Symbol`.
21+
/// - `#[derive(Service)]` with `#[service_symbol(FooSymbol)]` uses an explicit
22+
/// service symbol.
23+
///
24+
/// # Examples
25+
///
26+
/// Default symbol:
27+
///
28+
/// ```ignore
29+
/// use databend_common_base::base::Service;
30+
///
31+
/// #[derive(Service)]
32+
/// pub struct MyService;
33+
/// ```
34+
///
35+
/// Explicit symbol:
36+
///
37+
/// ```ignore
38+
/// use databend_common_base::base::Service;
39+
///
40+
/// pub struct FooSymbol;
41+
///
42+
/// #[derive(Service)]
43+
/// #[service_symbol(FooSymbol)]
44+
/// pub struct MyService;
45+
/// ```
1646
#[proc_macro_derive(Service, attributes(service_symbol))]
1747
pub fn derive_service(item: TokenStream) -> TokenStream {
1848
let input = parse_macro_input!(item as DeriveInput);
@@ -28,6 +58,72 @@ pub fn derive_service(item: TokenStream) -> TokenStream {
2858
}
2959
}
3060

61+
/// Assigns a `::databend_common_base::base::Service::Symbol` to a service type
62+
/// or `impl Service for ...` block.
63+
///
64+
/// Supported forms:
65+
/// - `#[service_symbol]` on a struct uses the default symbol
66+
/// `<TypeName>Symbol`.
67+
/// - `#[service_symbol(FooSymbol)]` on a struct uses an explicit symbol.
68+
/// - `#[service_symbol]` on an enum uses the default symbol
69+
/// `<TypeName>Symbol`.
70+
/// - `#[service_symbol(FooSymbol)]` on an enum uses an explicit symbol.
71+
/// - `#[service_symbol]` on a type alias uses the default symbol
72+
/// `<AliasName>Symbol`.
73+
/// - `#[service_symbol(FooSymbol)]` on a type alias uses an explicit symbol.
74+
/// - `#[service_symbol]` on `impl Service for T` uses the default symbol
75+
/// `<TypeName>Symbol`.
76+
/// - `#[service_symbol(FooSymbol)]` on `impl Service for T` uses an explicit
77+
/// symbol.
78+
///
79+
/// # Examples
80+
///
81+
/// Struct:
82+
///
83+
/// ```ignore
84+
/// use databend_common_base::base::service_symbol;
85+
///
86+
/// #[service_symbol]
87+
/// pub struct MyService;
88+
/// ```
89+
///
90+
/// Enum with an explicit symbol:
91+
///
92+
/// ```ignore
93+
/// use databend_common_base::base::service_symbol;
94+
///
95+
/// pub struct FooSymbol;
96+
///
97+
/// #[service_symbol(FooSymbol)]
98+
/// pub enum MyService {
99+
/// A,
100+
/// B,
101+
/// }
102+
/// ```
103+
///
104+
/// Type alias:
105+
///
106+
/// ```ignore
107+
/// use databend_common_base::base::service_symbol;
108+
///
109+
/// #[service_symbol]
110+
/// pub type BuildInfoRef = &'static BuildInfo;
111+
///
112+
/// pub struct BuildInfo;
113+
/// ```
114+
///
115+
/// Existing `impl Service for ...` block:
116+
///
117+
/// ```ignore
118+
/// use databend_common_base::base::Service;
119+
/// use databend_common_base::base::service_symbol;
120+
///
121+
/// pub struct FooSymbol;
122+
/// pub struct MyService;
123+
///
124+
/// #[service_symbol(FooSymbol)]
125+
/// impl Service for MyService {}
126+
/// ```
31127
#[proc_macro_attribute]
32128
pub fn service_symbol(attr: TokenStream, item: TokenStream) -> TokenStream {
33129
let item = parse_macro_input!(item as Item);

0 commit comments

Comments
 (0)