Skip to main content

fixed_type_id_macros/
lib.rs

1mod fixed_type_id;
2
3/// Macro to generate a unique id for trait object type or a general type.
4///
5/// This macro generates unique type IDs that can be used for type identification and casting.
6/// It supports both trait objects and concrete types, with optional version or file-based uniqueness.
7///
8/// For types with generic parameters, you should use **specific** type parameters when you're using this macro
9/// to define [`FixedTypeId`] for them.
10///
11/// # Examples
12///
13/// Basic usage with trait objects:
14/// ```
15/// # mod some {
16/// use fixed_type_id::fixed_type_id;
17/// use fixed_type_id::{FixedId, FixedTypeId, FixedVersion};
18///
19/// pub trait MyTrait {}
20///
21/// fixed_type_id! {
22///     dyn MyTrait
23/// }
24/// # }
25/// ```
26///
27/// With version-based uniqueness (commonly used pattern):
28/// ```
29///
30/// mod my_crate {
31///     mod api {
32///         use fixed_type_id::fixed_type_id;
33///         use fixed_type_id::{FixedId, FixedTypeId, FixedVersion};
34///         pub trait MyTrait {}
35///         fixed_type_id! {
36///             #[version((0,1,0))]
37///             dyn my_crate::api::MyTrait
38///         }
39///     }
40/// }
41/// ```
42///
43/// With file-based uniqueness and filename:
44/// ```
45/// # mod some {
46/// use fixed_type_id::fixed_type_id;
47/// use fixed_type_id::{FixedId, FixedTypeId, FixedVersion};
48///
49/// pub trait MyTrait {}
50///
51/// fixed_type_id! {
52///     #[store_in_file("ids.toml")]
53///     dyn MyTrait
54/// }
55/// # }
56/// ```
57///
58/// Real-world example from some APIs:
59/// ```ignore,no_compile
60/// use fixed_type_id::fixed_type_id;
61/// use fixed_type_id::{FixedId, FixedTypeId, FixedVersion};
62///
63/// fixed_type_id! {
64///     #[version((1,0,0))]
65///     dyn bubble_core::api::my_api::MyApi
66/// }
67/// ```
68#[proc_macro]
69pub fn fixed_type_id(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
70    fixed_type_id::fixed_type_id_impl(input)
71}