1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Lifecycle phases shared by stages that own resources.
//!
//! Source, sink, and pipeline implementations move through:
//!
//! 1. [`Lifecycle::init`] — acquire resources, validate config.
//! 2. [`Lifecycle::run`] — optional steady-state convenience loop.
//! 3. [`Lifecycle::shutdown`] — release resources deterministically.
//!
//! Not every pipeline concept implements this trait: pure
//! [`crate::PreProcessor`], [`crate::Placement`], [`crate::Decoder`],
//! [`crate::Encode`], and metrics collectors are typically driven by the
//! pipeline without their own resource lifecycle.
//!
//! ## Event-loop ownership
//!
//! The preferred driver is [`crate::Pipeline::step`]: one unit of
//! progress (pull → decode → route → write). [`Lifecycle::run`] is an
//! optional convenience that may loop `step` (or equivalent). Sources
//! expose `poll` / `poll_batch` for the pipeline to call; they should not
//! own the outer event loop when composed into a pipeline.
//!
//! ## State machine
//!
//! Illegal transitions (e.g. `run` before `init`, use after failed
//! `init`) should return [`crate::ErrorKind::Lifecycle`]. After
//! `shutdown`, the stage must not be used until `init` succeeds again.
//! `shutdown` is idempotent: calling it twice must not panic or
//! double-free. Partial failure during `init` must leave the stage safe
//! to drop or re-`init`.
use Result;
/// Lifecycle hooks for stages that own resources.