pub enum HoldSpec {
Frac(f64),
Fixed(Duration),
Loop {
interval: Duration,
},
}Expand description
How a step advances after its ops are applied. Frac and Fixed
hold for a duration; Loop repeatedly re-applies Step::ops at a
fixed interval instead of holding.
Construct via the constructor methods (Self::fixed,
Self::frac, Self::loop_at, or the Self::FULL const) —
variant syntax is reserved for pattern-matching in match arms.
Copy because every variant carries only Copy types (f64,
Duration); reuse the same HoldSpec value across multiple
Step::new / Step::with_defs / Step::with_payload
calls in a construction loop without an explicit .clone().
PartialEq is derived so tests can assert_eq!(step.hold, ...)
and user code can pattern-compare values directly — float
equality on Frac(f64) follows IEEE 754 semantics (so
HoldSpec::Frac(0.1 + 0.2) != HoldSpec::Frac(0.3), and
HoldSpec::Frac(f64::NAN) != HoldSpec::Frac(f64::NAN) —
Self::validate rejects NaN at intake so the non-reflexive
case is unreachable through validated construction, but the
derive inherits the IEEE 754 contract at the type level). Eq /
Hash remain impossible because Frac carries a float.
Variants§
Frac(f64)
Fraction of the total scenario duration.
Fixed(Duration)
Fixed duration.
Loop
Repeat the step’s ops in a loop at the given interval until the remaining scenario time is exhausted.
Implementations§
Source§impl HoldSpec
impl HoldSpec
Sourcepub const FULL: HoldSpec
pub const FULL: HoldSpec
Hold for the full scenario duration. Equivalent to
HoldSpec::frac(1.0) and resolves to
ctx.duration at scenario-run time.
Sourcepub const fn fixed(d: Duration) -> HoldSpec
pub const fn fixed(d: Duration) -> HoldSpec
Hold for a fixed wall-clock duration. Sugar for
HoldSpec::Fixed(d) that reads naturally in chain position
(Step::new(ops, HoldSpec::fixed(Duration::from_secs(5))))
and surfaces in IDE autocomplete next to Self::frac and
Self::loop_at.
For the common settle + duration * fraction pattern, prefer
Ctx::settled_hold over
HoldSpec::fixed(ctx.settle + ctx.duration.mul_f64(frac)).
Sourcepub const fn frac(f: f64) -> HoldSpec
pub const fn frac(f: f64) -> HoldSpec
Hold for a fraction of ctx.duration (the scenario duration
configured on crate::scenario::Ctx). Sugar for
HoldSpec::Frac(f); the resolved wall-clock hold is
ctx.duration * f (e.g. 0.5 = half the scenario
duration). f must be finite and > 0.0 — see
Self::validate for the rejection rules.
Sourcepub const fn loop_at(interval: Duration) -> HoldSpec
pub const fn loop_at(interval: Duration) -> HoldSpec
Repeat the step’s ops at the given interval until the
remaining scenario time is exhausted. Sugar for
HoldSpec::Loop { interval }; the value is interval. Must
be non-zero — see Self::validate for the rejection rule.
Named loop_at (verb-preposition) rather than r#loop
because the variant name Loop collides with the Rust
keyword loop — loop_at reads as “loop AT this interval”
and avoids the raw-identifier escape. Sibling constructors
Self::fixed / Self::frac match their variant names
directly (no keyword conflict).
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Reject hold values that are vacuous (no-op step) or would panic downstream.
Rules:
Fixed(Duration::ZERO)— valid for settle steps and op-only steps that apply changes without holding.Frac(f)with!f.is_finite()(NaN/Inf) — propagates intoDuration::from_secs_f64(f)which panics.Frac(f)withf <= 0.0— zero is vacuous, negative panics inDuration::from_secs_f64.Loop { interval: Duration::ZERO }— busy-polls the deadline loop without yielding; almost always a typo.
Trait Implementations§
impl Copy for HoldSpec
impl StructuralPartialEq for HoldSpec
Auto Trait Implementations§
impl Freeze for HoldSpec
impl RefUnwindSafe for HoldSpec
impl Send for HoldSpec
impl Sync for HoldSpec
impl Unpin for HoldSpec
impl UnwindSafe for HoldSpec
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,
§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>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more