use pavex_bp_schema::{Blueprint as BlueprintSchema, Component, PrebuiltType};
use crate::blueprint::{CloningPolicy, conversions::cloning2cloning};
use super::reflection::AnnotationCoordinates;
pub struct Prebuilt {
#[doc(hidden)]
pub coordinates: AnnotationCoordinates,
}
pub struct RegisteredPrebuilt<'a> {
#[allow(unused)]
pub(crate) blueprint: &'a mut BlueprintSchema,
#[allow(unused)]
pub(crate) component_id: usize,
}
impl RegisteredPrebuilt<'_> {
pub fn cloning(mut self, strategy: CloningPolicy) -> Self {
self.prebuilt().cloning_policy = Some(cloning2cloning(strategy));
self
}
pub fn clone_if_necessary(self) -> Self {
self.cloning(CloningPolicy::CloneIfNecessary)
}
pub fn never_clone(self) -> Self {
self.cloning(CloningPolicy::NeverClone)
}
fn prebuilt(&mut self) -> &mut PrebuiltType {
let component = &mut self.blueprint.components[self.component_id];
let Component::PrebuiltType(s) = component else {
unreachable!("The component should be a prebuilt type")
};
s
}
}