pub struct Ystep<T>{ /* private fields */ }Expand description
A step entity in a Y-axis progression with an associated numeric value.
Ystep represents a discrete point in a sequence, maintaining both an integer index
and an associated positive numeric value. This structure is designed to be used in
financial calculations, visualizations, or any context where tracking incremental
steps with corresponding values is needed.
The generic parameter T allows flexibility in the type of value stored, as long as
it can be converted into a Positive type, ensuring all values are valid non-negative numbers.
§Type Parameters
T- A type that can be converted into aPositivevalue. This ensures that all values stored inYstepare non-negative.
§Fields
-
index- An integer representing the step’s position in a sequence. -
value- A positive numeric value associated with this step.
Implementations§
Source§impl<T> Ystep<T>
A step value holder for simulation values that must be positive.
impl<T> Ystep<T>
A step value holder for simulation values that must be positive.
Ystep<T> maintains an index counter and a value of type T, where T
must be TryInto<Positive> + Display and convertible to a Positive value.
This struct is typically used in financial simulations where values need to be tracked across simulation steps while ensuring they remain positive.
§Type Parameters
T- The value type that must be convertible toPositive
§Examples
use rust_decimal_macros::dec;
use optionstratlib_simulation::simulation::steps::Ystep;
// Create a new step with initial value
let step = Ystep::new(1, dec!(10.5));
// Access the current value
assert_eq!(*step.value(), dec!(10.5));Sourcepub fn next(&self, value: T) -> Result<Self, SimulationError>
pub fn next(&self, value: T) -> Result<Self, SimulationError>
Creates a new step with an incremented index and the provided value.
This method produces a new step instance that represents the next step in a sequence, with an index one higher than the current step and storing the provided value.
§Parameters
value- The value to store in the new step
§Returns
A new Ystep<T> instance with incremented index
§Errors
Returns SimulationError::StepError when the index is already
i32::MAX. The raw + 1 used here aborted in debug builds and wrapped
to i32::MIN in release builds (#788).
Sourcepub fn value(&self) -> &T
pub fn value(&self) -> &T
Returns an immutable reference to the stored value.
§Returns
A reference to the stored value of type T
Sourcepub fn positive(&self) -> Result<Positive, SimulationError>
pub fn positive(&self) -> Result<Positive, SimulationError>
Returns an immutable reference to the stored value.
§Returns
A reference to the stored value of type T
§Errors
Returns SimulationError::PositiveError when the stored
y value cannot be converted to a Positive (NaN, negative,
or otherwise invalid for the Positive invariant).
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Ystep<T>where
T: Freeze,
impl<T> RefUnwindSafe for Ystep<T>where
T: RefUnwindSafe,
impl<T> Send for Ystep<T>where
T: Send,
impl<T> Sync for Ystep<T>where
T: Sync,
impl<T> Unpin for Ystep<T>where
T: Unpin,
impl<T> UnsafeUnpin for Ystep<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Ystep<T>where
T: UnwindSafe,
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.