Struct pavex::blueprint::constructor::RegisteredConstructor
source · pub struct RegisteredConstructor<'a> { /* private fields */ }
Expand description
The type returned by Blueprint::constructor
.
It allows you to further configure the behaviour of the registered constructor.
Implementations§
source§impl<'a> RegisteredConstructor<'a>
impl<'a> RegisteredConstructor<'a>
sourcepub fn error_handler(self, error_handler: RawIdentifiers) -> Self
pub fn error_handler(self, error_handler: RawIdentifiers) -> Self
Register an error handler.
If an error handler has already been registered for this constructor, it will be overwritten.
§Guide
Check out the “Error handlers” section of Pavex’s guide for a thorough introduction to error handlers in Pavex applications.
§Example
use pavex::f;
use pavex::blueprint::{Blueprint, constructor::Lifecycle};
use pavex::response::Response;
// 👇 a fallible constructor
fn logger() -> Result<Logger, ConfigurationError> {
// [...]
}
fn error_to_response(error: &ConfigurationError, log_level: LogLevel) -> Response {
// [...]
}
let mut bp = Blueprint::new();
bp.constructor(f!(crate::logger), Lifecycle::Transient)
.error_handler(f!(crate::error_to_response));
sourcepub fn cloning(self, strategy: CloningStrategy) -> Self
pub fn cloning(self, strategy: CloningStrategy) -> Self
Set the cloning strategy for the output type returned by this constructor.
By default,
Pavex will never try to clone the output type returned by a constructor.
If the output type implements Clone
, you can change the default by setting the cloning strategy
to CloningStrategy::CloneIfNecessary
: Pavex will clone the output type if
it’s necessary to generate code that satisfies Rust’s borrow checker.
sourcepub fn clone_if_necessary(self) -> Self
pub fn clone_if_necessary(self) -> Self
Set the cloning strategy to CloningStrategy::CloneIfNecessary
.
Check out RegisteredConstructor::cloning
for more details.
sourcepub fn never_clone(self) -> Self
pub fn never_clone(self) -> Self
Set the cloning strategy to CloningStrategy::NeverClone
.
Check out RegisteredConstructor::cloning
for more details.