pavex/blueprint/reflection.rs
1//! Metadata used by Pavex's CLI to analyze your request
2//! handlers, constructors, error handlers, error observers (e.g. their input parameters, their return type,
3//! where they are defined, etc.), etc.
4//!
5//! This module is not meant to be used directly by users of the framework. It is only meant to be
6//! used by Pavex's CLI.
7use std::borrow::Cow;
8
9/// The modules you want to import components from.
10pub enum Sources {
11 /// Use all valid sources: all components defined in the current crate and its direct dependencies.
12 All,
13 /// Use only the specified modules as sources.
14 ///
15 /// Each module can be either from the current crate or from one of its direct dependencies.
16 Some(Vec<Cow<'static, str>>),
17}
18
19/// Metadata about an annotated component.
20///
21/// It is used by Pavex to retrieve the component's location and match the information in the annotation
22/// with those provided when the component was registered with the [`Blueprint`](crate::Blueprint).
23///
24/// # Stability
25///
26/// Newer versions of Pavex may introduce, remove or modify the fields of this struct—it is considered
27/// an implementation detail of Pavex's macros and should not be used directly.
28#[derive(Debug)]
29pub struct AnnotationCoordinates {
30 #[doc(hidden)]
31 /// The identifier of the component.
32 ///
33 /// It must be unique within the crate where the component was defined.
34 pub id: &'static str,
35 #[doc(hidden)]
36 /// Metadata to identify the location where the component was defined.
37 pub created_at: CreatedAt,
38 #[doc(hidden)]
39 /// The name of the macro attribute used to create the component.
40 pub macro_name: &'static str,
41}
42
43/// Metadata about the module where a Pavex macro was invoked to create a component.
44///
45/// It is used by Pavex to:
46///
47/// - unambiguously identify in which crate of your dependency tree a component was created
48/// - convert relative import paths to absolute paths starting from the root of the relevant crate
49///
50/// # Stability
51///
52/// `CreatedAt` fields are always populated by Pavex's macros.
53/// Newer versions of Pavex may introduce, remove or modify the fields of this struct—it is considered
54/// an implementation detail of Pavex's macros and should not be used directly.
55#[derive(Debug)]
56pub struct CreatedAt {
57 /// The name of the Cargo package where the value was created.
58 #[doc(hidden)]
59 pub package_name: &'static str,
60 /// The version of the Cargo package where the value was created.
61 #[doc(hidden)]
62 pub package_version: &'static str,
63}
64
65#[macro_export]
66#[doc(hidden)]
67/// A convenience macro to initialize a [`CreatedAt`] instance.
68macro_rules! created_at {
69 () => {
70 $crate::blueprint::reflection::CreatedAt {
71 package_name: ::std::env!("CARGO_PKG_NAME", "Failed to load the CARGO_PKG_NAME environment variable. Are you using a custom build system?"),
72 package_version: ::std::env!("CARGO_PKG_VERSION", "Failed to load the CARGO_PKG_VERSION environment variable. Are you using a custom build system?"),
73 }
74 };
75}