pub struct PlaybookResolver { /* private fields */ }Expand description
Playbook registry + precedence resolver.
§Example
use stygian_charon::playbooks::{PlaybookOverrides, PlaybookResolver};
use stygian_charon::types::TargetClass;
let resolver = PlaybookResolver::with_builtin_defaults();
let resolved = resolver
.resolve(
TargetClass::ContentSite,
"tier1-js",
&PlaybookOverrides::default(),
)
.expect("resolve");
assert_eq!(resolved.target_class, TargetClass::ContentSite);Implementations§
Source§impl PlaybookResolver
impl PlaybookResolver
Sourcepub fn with_builtin_defaults() -> Self
pub fn with_builtin_defaults() -> Self
Create a resolver seeded with the documented baseline
playbooks (tier1-static, tier1-js, tier2-hostile,
plus an unknown fallback).
The resolver will fail-fast on startup if any embedded
playbook is invalid; this guarantees the loader’s
validate()-first contract.
§Panics
Panics if any embedded baseline TOML fails to parse or
validate. This is a compile-time failure guarded by
the compile_check_builtin_playbooks test in
crate::playbooks::builtin; the panic in production
surfaces a regression in the embedded data as a hard
startup error.
§Example
use stygian_charon::playbooks::PlaybookResolver;
let resolver = PlaybookResolver::with_builtin_defaults();
assert!(resolver.contains("tier1-static"));
assert!(resolver.contains("tier1-js"));
assert!(resolver.contains("tier2-hostile"));Sourcepub fn from_playbooks<I>(playbooks: I) -> Result<Self, ValidationError>where
I: IntoIterator<Item = Playbook>,
pub fn from_playbooks<I>(playbooks: I) -> Result<Self, ValidationError>where
I: IntoIterator<Item = Playbook>,
Build a resolver from a list of pre-validated playbooks. The first playbook encountered per target class becomes the default for that class; subsequent matches for the same class override the lookup (last-write-wins).
§Errors
Returns ValidationError::DuplicateId when two playbooks
share the same id, or ValidationError from each playbook’s
validate().
Sourcepub fn contains(&self, id: &str) -> bool
pub fn contains(&self, id: &str) -> bool
true when the resolver has a playbook with the given id.
Sourcepub fn playbook_ids(&self) -> Vec<String>
pub fn playbook_ids(&self) -> Vec<String>
Ids of all registered playbooks, in sorted order.
Sourcepub fn resolve(
&self,
target_class: TargetClass,
playbook_id: &str,
overrides: &PlaybookOverrides,
) -> Result<ResolvedPlaybook, ValidationError>
pub fn resolve( &self, target_class: TargetClass, playbook_id: &str, overrides: &PlaybookOverrides, ) -> Result<ResolvedPlaybook, ValidationError>
Resolve a playbook for a (target_class, playbook_id) pair
with per-request overrides. Precedence:
request override > playbook default > global default.
When playbook_id is Some and registered, the playbook is
used directly. When playbook_id is None, the resolver
looks up the target-class default. When neither resolves,
the resolver falls through to the global default.
§Errors
Returns ValidationError::UnknownPlaybook when an explicit
playbook_id is supplied and is not registered.
§Example
use stygian_charon::playbooks::{PlaybookOverrides, PlaybookResolver};
use stygian_charon::types::TargetClass;
let resolver = PlaybookResolver::with_builtin_defaults();
let resolved = resolver
.resolve(
TargetClass::ContentSite,
"tier1-js",
&PlaybookOverrides::default(),
)
.expect("resolve");
assert_eq!(resolved.playbook_id, "tier1-js");Sourcepub fn resolve_optional(
&self,
target_class: TargetClass,
playbook_id: Option<&str>,
overrides: &PlaybookOverrides,
) -> Result<ResolvedPlaybook, ValidationError>
pub fn resolve_optional( &self, target_class: TargetClass, playbook_id: Option<&str>, overrides: &PlaybookOverrides, ) -> Result<ResolvedPlaybook, ValidationError>
Like resolve but takes an optional
playbook_id and falls through to the target-class default
(or the global default) when None.
§Errors
Returns ValidationError::UnknownPlaybook when an explicit
playbook_id is supplied and is not registered.
§Example
use stygian_charon::playbooks::{PlaybookOverrides, PlaybookResolver};
use stygian_charon::types::TargetClass;
let resolver = PlaybookResolver::with_builtin_defaults();
let resolved = resolver
.resolve_optional(
TargetClass::ContentSite,
None,
&PlaybookOverrides::default(),
)
.expect("resolve");
assert!(resolver.contains(&resolved.playbook_id));Trait Implementations§
Source§impl Clone for PlaybookResolver
impl Clone for PlaybookResolver
Source§fn clone(&self) -> PlaybookResolver
fn clone(&self) -> PlaybookResolver
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more