blob: 4aac258b1f04fbcc1411f4706cf025d26e14f512 [file] [log] [blame]
Marcel Hlopko2631d5a2022-04-13 10:10:21 -07001// Part of the Crubit project, under the Apache License v2.0 with LLVM
2// Exceptions. See /LICENSE for license information.
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5/// The `cc_template!` macro tells the C++ / Rust interop tooling to instantiate
6/// the specified C++ class template with the given arguments. The tooling will
7/// generate bindings for the instantiation, and the macro will expand to a type
8/// path for the Rust struct representing the instantiation.
9///
10/// Example:
11/// Consider the following snippet of Rust code:
12/// ```rust
13/// fn make_bool_vector() -> cc_template!(std::vector<bool>) {...}
14/// ```
15/// The C++ / Rust interop tooling will detect the use of the `cc_template!`
16/// macro with `std::vector<bool>` as an argument. The tooling will generate
17/// bindings for the instantiation and it will expand to something like:
18/// ```rust
19/// fn make_bool_vector() ->
20/// __cc_template_instantiations_rs_api::__CcTemplateInstSt6VectorIbE {
21/// ...
22/// }
23/// ```
24#[proc_macro]
25pub fn cc_template(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
26 cc_template_impl::to_private_struct_path(input.into())
27 .unwrap_or_else(|err| err.into_compile_error())
28 .into()
29}