Skip to content

Commit bd366f4

Browse files
chore: Remove pavex_reflection crate.
Its types aren't meaningfully different from what you could already find in `pavex_bp_schema`. We can simplify our setup by removing `pavex_reflection` entirely and replacing re-exports with definitions in `pavex_bp_schema`.
1 parent 36351c8 commit bd366f4

File tree

11 files changed

+123
-169
lines changed

11 files changed

+123
-169
lines changed

libs/Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/pavex/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ http-body-util = { workspace = true }
4242
pin-project-lite = { workspace = true }
4343
ubyte = { workspace = true, features = ["serde"] }
4444
pavex_bp_schema = { path = "../pavex_bp_schema", version = "=0.2.7" }
45-
pavex_reflection = { path = "../pavex_reflection", version = "=0.2.7" }
4645
persist_if_changed = { path = "../persist_if_changed", version = "0.2.7" }
4746

4847
# Configuration

libs/pavex/src/blueprint/blueprint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::{
2121
use crate::blueprint::RegisteredErrorObserver;
2222
use crate::blueprint::RegisteredPrebuilt;
2323
use pavex_bp_schema::Blueprint as BlueprintSchema;
24-
use pavex_reflection::Location;
24+
use pavex_bp_schema::Location;
2525

2626
/// The structure of your Pavex application.
2727
///

libs/pavex/src/blueprint/conversions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::blueprint::{CloningPolicy, Lifecycle};
66
#[track_caller]
77
pub(super) fn coordinates2coordinates(
88
c: AnnotationCoordinates,
9-
) -> pavex_reflection::AnnotationCoordinates {
10-
pavex_reflection::AnnotationCoordinates {
9+
) -> pavex_bp_schema::AnnotationCoordinates {
10+
pavex_bp_schema::AnnotationCoordinates {
1111
id: c.id.to_owned(),
1212
created_at: created_at2created_at(c.created_at),
1313
macro_name: c.macro_name.to_owned(),

libs/pavex_bp_schema/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ license.workspace = true
99

1010
[dependencies]
1111
serde = { workspace = true, features = ["derive"] }
12-
pavex_reflection = { path = "../pavex_reflection", version = "=0.2.7" }

libs/pavex_bp_schema/src/lib.rs

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//!
33
//! There are no guarantees that this schema will remain stable across Pavex versions:
44
//! it is considered (for the time being) an internal implementation detail of Pavex's reflection system.
5-
use pavex_reflection::AnnotationCoordinates;
6-
pub use pavex_reflection::{CreatedAt, CreatedBy, Location};
75
use std::collections::{BTreeMap, BTreeSet};
86
use std::fmt;
97
use std::fmt::Formatter;
@@ -363,3 +361,121 @@ pub enum Sources {
363361
/// Each module can be either from the current crate or from one of its direct dependencies.
364362
Some(Vec<String>),
365363
}
364+
365+
#[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
366+
/// A set of coordinates to identify a precise spot in a source file.
367+
///
368+
/// # Implementation Notes
369+
///
370+
/// `Location` is an owned version of [`std::panic::Location`].
371+
/// You can build a `Location` instance starting from a [`std::panic::Location`]:
372+
///
373+
/// ```rust
374+
/// use pavex_reflection::Location;
375+
///
376+
/// let location: Location = std::panic::Location::caller().into();
377+
/// ```
378+
pub struct Location {
379+
/// The line number.
380+
///
381+
/// Lines are 1-indexed (i.e. the first line is numbered as 1, not 0).
382+
pub line: u32,
383+
/// The column number.
384+
///
385+
/// Columns are 1-indexed (i.e. the first column is numbered as 1, not 0).
386+
pub column: u32,
387+
/// The name of the source file.
388+
///
389+
/// Check out [`std::panic::Location::file`] for more details.
390+
pub file: String,
391+
}
392+
393+
impl<'a> From<&'a std::panic::Location<'a>> for Location {
394+
fn from(l: &'a std::panic::Location<'a>) -> Self {
395+
Self {
396+
line: l.line(),
397+
column: l.column(),
398+
file: l.file().into(),
399+
}
400+
}
401+
}
402+
403+
impl Location {
404+
#[track_caller]
405+
pub fn caller() -> Self {
406+
std::panic::Location::caller().into()
407+
}
408+
}
409+
410+
#[derive(Debug, Hash, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
411+
/// The method used to create (and set the properties) for this component.
412+
pub enum CreatedBy {
413+
/// The component was created via a macro annotation (e.g. `#[pavex::wrap]`)
414+
/// on top of the target item (e.g. a function or a method).
415+
Attribute { name: String },
416+
/// The component was provided by the framework.
417+
///
418+
/// For example, the default fallback handler if the user didn't specify one.
419+
Framework,
420+
}
421+
422+
impl CreatedBy {
423+
/// Convert the name of the macro used to perform the registration into an instance of [`CreatedBy`].
424+
pub fn macro_name(value: &str) -> Self {
425+
match value {
426+
"pre_process" | "post_process" | "wrap" | "request_scoped" | "transient"
427+
| "singleton" | "config" | "error_handler" | "error_observer" | "fallback"
428+
| "route" => CreatedBy::Attribute { name: value.into() },
429+
_ => panic!(
430+
"Pavex doesn't recognize `{value}` as one of its macros to register components"
431+
),
432+
}
433+
}
434+
}
435+
436+
#[derive(Debug, Hash, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
437+
pub struct AnnotationCoordinates {
438+
/// An opaque string that uniquely identifies this component within the package
439+
/// where it was defined.
440+
pub id: String,
441+
/// Metadata required to pinpoint where the annotated component lives.
442+
pub created_at: CreatedAt,
443+
/// The name of the macro used to annotate the component.
444+
pub macro_name: String,
445+
}
446+
447+
#[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
448+
/// Information on the crate/module where the component was created.
449+
///
450+
/// This location matches, for example, where the `from!` or the `f!` macro were invoked.
451+
/// For annotated items (e.g. via `#[pavex::config]`), this refers to the location of the annotation.
452+
///
453+
/// It may be different from the location where the component was registered
454+
/// with the blueprint—i.e. where a `Blueprint` method was invoked.
455+
pub struct CreatedAt {
456+
/// The name of the crate that created the component, as it appears in the `package.name` field
457+
/// of its `Cargo.toml`.
458+
/// Obtained via [`CARGO_PKG_NAME`](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates).
459+
///
460+
/// In particular, the name has *not* been normalised—e.g. hyphens are not replaced with underscores.
461+
///
462+
/// This information is needed to resolve the import path unambiguously.
463+
///
464+
/// E.g. `my_crate::module_1::type_2`—which crate is `my_crate`?
465+
/// This is not obvious due to the possibility of [renaming dependencies in `Cargo.toml`](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html?highlight=rename,depende#renaming-dependencies-in-cargotoml):
466+
///
467+
/// ```toml
468+
/// [package]
469+
/// name = "mypackage"
470+
/// version = "0.0.1"
471+
///
472+
/// [dependencies]
473+
/// my_crate = { version = "0.1", registry = "custom", package = "their_crate" }
474+
/// ```
475+
pub package_name: String,
476+
/// The version of the crate that created the component, as it appears in the `package.version` field
477+
/// of its `Cargo.toml`.
478+
///
479+
/// Obtained via [`CARGO_PKG_VERSION`](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates).
480+
pub package_version: String,
481+
}

libs/pavex_reflection/Cargo.toml

Lines changed: 0 additions & 11 deletions
This file was deleted.

libs/pavex_reflection/src/lib.rs

Lines changed: 0 additions & 117 deletions
This file was deleted.

libs/pavexc/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ debug_assertions = []
2525
pavex = { path = "../pavex", version = "0.2.7" }
2626
pavexc_attr_parser = { path = "../pavexc_attr_parser", version = "=0.2.7" }
2727
pavex_bp_schema = { path = "../pavex_bp_schema", version = "=0.2.7" }
28-
pavex_reflection = { path = "../pavex_reflection", version = "=0.2.7" }
2928
pavex_cli_shell = { path = "../pavex_cli_shell", version = "=0.2.7" }
3029
pavex_cli_diagnostic = { path = "../pavex_cli_diagnostic", version = "=0.2.7" }
3130
rustdoc-types = { workspace = true }

libs/pavexc/src/compiler/analyses/user_components/blueprint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ fn _process_blueprint<'a>(
239239
// If the user hasn't registered one against the top-level blueprint,
240240
// we use the framework's default one.
241241
is_root.then(|| Fallback {
242-
coordinates: pavex_reflection::AnnotationCoordinates {
242+
coordinates: pavex_bp_schema::AnnotationCoordinates {
243243
id: "DEFAULT_FALLBACK".into(),
244244
created_at: CreatedAt {
245245
package_name: "pavex".to_owned(),

0 commit comments

Comments
 (0)