Skip to main content

jigs_core/
meta.rs

1//! Compile-time metadata for every `#[jig]` function in the binary.
2//!
3//! The `#[jig]` macro emits one [`JigMeta`] per annotated function and
4//! registers it via the `inventory` crate. Consumers iterate them at runtime
5//! through [`all`].
6
7/// Static description of one jig.
8#[derive(Debug, Clone, Copy)]
9pub struct JigMeta {
10    /// Function name as written in source.
11    pub name: &'static str,
12    /// Source file path (as seen by the compiler at expansion time).
13    pub file: &'static str,
14    /// 1-based line of the function declaration.
15    pub line: u32,
16    /// Outer return-type identifier: `"Request"`, `"Response"`, `"Branch"`,
17    /// `"Pending"`, or `"Other"`.
18    pub kind: &'static str,
19    /// Outer first-argument type identifier: `"Request"`, `"Response"`, or
20    /// `"Other"`. Combined with [`Self::kind`] this places a jig in one of three
21    /// semantic buckets: request-side (Request → Request), switching
22    /// (Request → Response/Branch) or response-side (Response → Response).
23    pub input: &'static str,
24    /// `true` if the underlying function is `async fn`.
25    pub is_async: bool,
26    /// Names of jigs this function calls via `.then(IDENT)`, in chain order.
27    pub chain: &'static [&'static str],
28}
29
30inventory::collect!(JigMeta);
31
32/// Iterator over every jig registered in the current binary.
33pub fn all() -> impl Iterator<Item = &'static JigMeta> {
34    inventory::iter::<JigMeta>()
35}
36
37/// Look up a jig by name. `O(N)` over the registry.
38pub fn find(name: &str) -> Option<&'static JigMeta> {
39    all().find(|m| m.name == name)
40}