Skip to main content

Ystep

Struct Ystep 

Source
pub struct Ystep<T>
where T: TryInto<Positive> + Display + Clone,
{ /* 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 a Positive value. This ensures that all values stored in Ystep are 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>
where T: TryInto<Positive> + Display + Clone,

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 to Positive

§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));
Source

pub fn new(index: i32, value: T) -> Self

Creates a new Ystep instance with the specified value.

The index is initialized to 0 and the provided value is stored.

§Parameters
  • value - The initial value to store
§Returns

A new Ystep<T> instance

Source

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).

Source

pub fn value(&self) -> &T

Returns an immutable reference to the stored value.

§Returns

A reference to the stored value of type T

Source

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).

Source

pub fn index(&self) -> &i32

Returns an immutable reference to the index of this step.

The index represents the step’s position in a sequence, typically indicating how many steps have occurred since initialization.

§Returns

A reference to the index as an i32 value

Source

pub fn value_mut(&mut self) -> &mut T

Returns a mutable reference to the stored value.

This allows modifying the value while maintaining the Ystep structure.

§Returns

A mutable reference to the stored value of type T

Trait Implementations§

Source§

impl<T> Clone for Ystep<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Ystep<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Display for Ystep<T>
where T: TryInto<Positive> + Display + Clone,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Serialize for Ystep<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> TryFrom<Ystep<T>> for Positive
where T: TryInto<Positive> + Display + Clone,

Source§

type Error = SimulationError

The type returned in the event of a conversion error.
Source§

fn try_from(step: Ystep<T>) -> Result<Self, Self::Error>

Performs the conversion.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more