quilkin_macros/lib.rs
1/*
2 * Copyright 2021 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17mod include;
18
19use quote::ToTokens;
20use syn::parse_macro_input;
21
22use include::IncludeProto;
23
24/// Includes generated Protobuf definitions from `tonic`.
25///
26/// Accepts a single argument for the gRPC package name, which then recreates
27/// the package structure as modules.
28///
29/// ### Input
30/// ```
31/// quilkin::include_proto!("quilkin.filters.debug.v1alpha1");
32/// ```
33///
34/// ### Output
35/// ```
36/// mod quilkin {
37/// pub(crate) mod extensions {
38/// pub(crate) mod filters {
39/// pub(crate) mod debug {
40/// pub(crate) mod v1alpha1 {
41/// #![doc(hidden)]
42/// tonic::include_proto!("quilkin.filters.debug.v1alpha1");
43/// }
44/// }
45/// }
46/// }
47/// }
48/// ```
49#[proc_macro]
50pub fn include_proto(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
51 parse_macro_input!(input as IncludeProto)
52 .to_token_stream()
53 .into()
54}