pub struct SupervisorTree {
pub root_path: SupervisorPath,
pub nodes: Vec<SupervisorTreeNode>,
}Expand description
Built supervisor tree with stable declaration order.
Fields§
§root_path: SupervisorPathRoot supervisor path.
nodes: Vec<SupervisorTreeNode>Nodes in declaration order.
Implementations§
Source§impl SupervisorTree
impl SupervisorTree
Sourcepub fn build(spec: &SupervisorSpec) -> Result<Self, SupervisorError>
pub fn build(spec: &SupervisorSpec) -> Result<Self, SupervisorError>
Builds a tree from a supervisor specification.
§Arguments
spec: Supervisor declaration to index.
§Returns
Returns a SupervisorTree when child identifiers and paths are valid.
§Examples
let spec = rust_supervisor::spec::supervisor::SupervisorSpec::root(Vec::new());
let tree = rust_supervisor::tree::builder::SupervisorTree::build(&spec).unwrap();
assert!(tree.nodes.is_empty());Examples found in repository?
25fn main() -> ExampleResult {
26 // Build the market feed child.
27 let mut market_feed = worker("market_feed", "Market Feed");
28 // Add low-cardinality market feed tags.
29 market_feed.tags = vec!["market".to_owned(), "network".to_owned()];
30 // Require explicit readiness for the market feed.
31 market_feed.readiness_policy = ReadinessPolicy::Explicit;
32
33 // Build the risk engine child.
34 let mut risk_engine = worker("risk_engine", "Risk Engine");
35 // Make the risk engine depend on the market feed.
36 risk_engine.dependencies = vec![market_feed.id.clone()];
37 // Add low-cardinality risk engine tags.
38 risk_engine.tags = vec!["risk".to_owned()];
39
40 // Build the audit sink child.
41 let mut audit_sink = worker("audit_sink", "Audit Sink");
42 // Mark the audit sink as optional.
43 audit_sink.criticality = Criticality::Optional;
44 // Add low-cardinality audit tags.
45 audit_sink.tags = vec!["audit".to_owned()];
46
47 // Build the root supervisor specification.
48 let mut spec = SupervisorSpec::root(vec![market_feed.clone(), risk_engine, audit_sink]);
49 // Select the RestForOne restart strategy.
50 spec.strategy = SupervisionStrategy::RestForOne;
51 // Set an example configuration version.
52 spec.config_version = "examples-supervisor-tree-story".to_owned();
53
54 // Build the indexed supervisor tree.
55 let tree = SupervisorTree::build(&spec)?;
56 // Print the root supervisor path.
57 println!("root_path={}", tree.root_path);
58 // Print startup order by child name.
59 println!("startup_order={:?}", child_names(startup_order(&tree)));
60 // Print shutdown order by child name.
61 println!("shutdown_order={:?}", child_names(shutdown_order(&tree)));
62 // Print the restart scope after market feed failure.
63 println!(
64 // Provide the output template.
65 "restart_scope_after_market_feed={:?}",
66 // Calculate the restart scope.
67 restart_scope(&tree, spec.strategy, &market_feed.id),
68 // Finish printing the restart scope.
69 );
70
71 // Finish the example successfully.
72 Ok(())
73 // End the supervisor tree example.
74}Sourcepub fn child_path(&self, child_id: &ChildId) -> Option<SupervisorPath>
pub fn child_path(&self, child_id: &ChildId) -> Option<SupervisorPath>
Sourcepub fn nested_supervisors(&self) -> Vec<&SupervisorTreeNode>
pub fn nested_supervisors(&self) -> Vec<&SupervisorTreeNode>
Trait Implementations§
Source§impl Clone for SupervisorTree
impl Clone for SupervisorTree
Source§fn clone(&self) -> SupervisorTree
fn clone(&self) -> SupervisorTree
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SupervisorTree
impl !RefUnwindSafe for SupervisorTree
impl Send for SupervisorTree
impl Sync for SupervisorTree
impl Unpin for SupervisorTree
impl UnsafeUnpin for SupervisorTree
impl !UnwindSafe for SupervisorTree
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§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();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§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();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§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();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§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();Source§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>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§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);