pub enum Schedule {
Repeating {
value_type: ValueType,
value: f64,
periods: u32,
},
Custom {
value_type: ValueType,
values: Vec<f64>,
},
}Expand description
Sparse or repeating schedule of rates or payments.
Construct with Schedule::new_repeating / Schedule::new_custom
(fallible FinanceResult) so non-finite values are rejected without panicking.
§Examples
use finance_solution::{Schedule, ValueType};
// Repeating 5% for three periods
let rates = Schedule::new_repeating(ValueType::Rate, 0.05, 3)?;
assert_eq!(rates.len(), 3);
assert_eq!(rates.get(0), Some(0.05));
assert_eq!(rates.get(3), None); // OOB → Option, not panic
// Custom payment ladder
let pmts = Schedule::new_custom(ValueType::Payment, &[100.0, 110.0, 120.0])?;
assert_eq!(pmts.get(1), Some(110.0));
// Invalid input is Err, not abort
assert!(Schedule::new_repeating(ValueType::Rate, f64::NAN, 1).is_err());
assert!(Schedule::new_custom(ValueType::Payment, &[]).is_err());Variants§
Implementations§
Source§impl Schedule
impl Schedule
Sourcepub fn new_repeating(
value_type: ValueType,
value: f64,
periods: u32,
) -> FinanceResult<Self>
pub fn new_repeating( value_type: ValueType, value: f64, periods: u32, ) -> FinanceResult<Self>
Sourcepub fn new_custom(value_type: ValueType, values: &[f64]) -> FinanceResult<Self>
pub fn new_custom(value_type: ValueType, values: &[f64]) -> FinanceResult<Self>
Custom value series (one entry per period).
§Errors
FinanceError::NonFinite if any value is not finite;
FinanceError::EmptyInput if values is empty.
pub fn is_payment(&self) -> bool
pub fn is_rate(&self) -> bool
pub fn value_type(&self) -> &ValueType
Sourcepub fn value(&self) -> Option<f64>
pub fn value(&self) -> Option<f64>
Constant value for a repeating schedule; None for custom series.
Sourcepub fn get(&self, index: usize) -> Option<f64>
pub fn get(&self, index: usize) -> Option<f64>
Value at a 0-based index, or None if out of range.
pub fn is_empty(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Schedule
impl RefUnwindSafe for Schedule
impl Send for Schedule
impl Sync for Schedule
impl Unpin for Schedule
impl UnsafeUnpin for Schedule
impl UnwindSafe for Schedule
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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 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> ⓘ
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