pub struct RegisteredConfig<'a> { /* private fields */ }Expand description
A configuration type registered via Blueprint::config.
§Example
You can use the methods exposed by RegisteredConfig to tune the behaviour
of the registered configuration type.
For example, instruct Pavex to use the Default implementation if the user configuration
doesn’t specify a value for pool:
use pavex::{config, Blueprint};
#[config(key = "pool")]
#[derive(serde::Deserialize, Debug, Clone)]
pub struct PoolConfig {
pub max_n_connections: u32,
pub min_n_connections: u32,
}
impl Default for PoolConfig {
fn default() -> Self {
Self {
max_n_connections: 10,
min_n_connections: 2,
}
}
}
let mut bp = Blueprint::new();
// This is equivalent to `#[config(key = "pool", default_if_missing)]`
bp.config(POOL_CONFIG).default_if_missing();§Example: override the annotation
You can also override the behaviour specified via the config attribute.
use pavex::{config, Blueprint};
#[config(key = "pool", default_if_missing)]
#[derive(serde::Deserialize, Debug, Clone)]
pub struct PoolConfig {
pub max_n_connections: u32,
pub min_n_connections: u32,
}
let mut bp = Blueprint::new();
// Using `required`, we are overriding the `default_if_missing` flag
// specified via the `config` attribute.
// This is equivalent to `#[config(key = "pool")]`, thus restoring
// the default behaviour.
bp.config(POOL_CONFIG).required();Implementations§
Source§impl RegisteredConfig<'_>
impl RegisteredConfig<'_>
Sourcepub fn cloning(self, strategy: CloningPolicy) -> Self
pub fn cloning(self, strategy: CloningPolicy) -> Self
Set the cloning strategy for this configuration type.
By default, Pavex will clone a configuration type if it’s necessary to generate code
that satisfies Rust’s borrow checker.
You can change the default behaviour by invoking never_clone.
Regardless of the chosen strategy, configuration types must implement Clone,
since the code-generated ApplicationConfig type will need to derive it.
Sourcepub fn clone_if_necessary(self) -> Self
pub fn clone_if_necessary(self) -> Self
Set the cloning strategy to CloningPolicy::CloneIfNecessary.
Check out cloning method for more details.
Sourcepub fn never_clone(self) -> Self
pub fn never_clone(self) -> Self
Set the cloning strategy to CloningPolicy::NeverClone.
Check out cloning method for more details.
Sourcepub fn default_if_missing(self) -> Self
pub fn default_if_missing(self) -> Self
Use the default configuration values returned by Default::default
if the user has not specified its own configuration for this type.
§Requirements
The configuration type must implement the Default trait
to support this option.
§Implementation notes
default_if_missing adds a #[serde(default)] attribute on the corresponding
configuration key in the code-generated ApplicationConfig struct.
Sourcepub fn required(self) -> Self
pub fn required(self) -> Self
Force the user to specify a value for this configuration entry.
It’s the opposite of default_if_missing.
Sourcepub fn include_if_unused(self) -> Self
pub fn include_if_unused(self) -> Self
Include this configuration entry in the generated ApplicationConfig struct
even if the type is never used by the application.
Auto Trait Implementations§
impl<'a> Freeze for RegisteredConfig<'a>
impl<'a> RefUnwindSafe for RegisteredConfig<'a>
impl<'a> Send for RegisteredConfig<'a>
impl<'a> Sync for RegisteredConfig<'a>
impl<'a> Unpin for RegisteredConfig<'a>
impl<'a> !UnwindSafe for RegisteredConfig<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);