Skip to main content

Period

Struct Period 

Source
pub struct Period { /* private fields */ }
Expand description

A time span expressed as an integer length of a given TimeUnit.

The length may be negative to express a span into the past. Equality and ordering are semantic (12 Months == 1 Year), not structural; see the module docs for the partial-order behaviour.

Implementations§

Source§

impl Period

Source

pub fn new(n: Integer, units: TimeUnit) -> Period

Builds a period of n units.

Source

pub fn length(&self) -> Integer

The (signed) number of units in the period.

Source

pub fn units(&self) -> TimeUnit

The unit the period is measured in.

Source

pub fn normalize(&mut self)

Rewrites the period into a canonical unit where possible: a zero length becomes Days, a whole number of months collapses to years, and a whole number of days collapses to weeks. Weeks and years are already canonical.

§Panics

Panics if the period uses a sub-day unit, which has no place in the calendar algebra (matching QuantLib’s QL_FAIL).

Source

pub fn normalized(&self) -> Period

Returns a normalized copy, leaving self untouched.

Source

pub fn frequency(&self) -> Frequency

The Frequency this period corresponds to, or OtherFrequency when it maps to none of the named ones (e.g. 5 Years). A zero length is Once for years and NoFrequency otherwise.

§Panics

Panics if the period uses a sub-day unit (matching QuantLib’s QL_FAIL).

Trait Implementations§

Source§

impl Add for Period

Source§

type Output = Period

The resulting type after applying the + operator.
Source§

fn add(self, p: Period) -> Period

Performs the + operation. Read more
Source§

impl Add<Period> for Date

Source§

type Output = Date

The resulting type after applying the + operator.
Source§

fn add(self, p: Period) -> Date

Performs the + operation. Read more
Source§

impl AddAssign for Period

Source§

fn add_assign(&mut self, p: Period)

Adds p in place, converting units where the algebra allows.

§Panics

Panics on an impossible addition, e.g. a non-zero Days period added to a Years one (matching QuantLib’s QL_REQUIRE).

Source§

impl Clone for Period

Source§

fn clone(&self) -> Period

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 Copy for Period

Source§

impl Debug for Period

Source§

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

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

impl Default for Period

Source§

fn default() -> Period

The empty span, 0 Days (QuantLib’s default-constructed Period).

Source§

impl Display for Period

Source§

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

Short format, e.g. 2W, 3M, -1Y (QuantLib’s io::short_period).

Source§

impl Div<i32> for Period

Source§

type Output = Period

The resulting type after applying the / operator.
Source§

fn div(self, n: Integer) -> Period

Performs the / operation. Read more
Source§

impl DivAssign<i32> for Period

Source§

fn div_assign(&mut self, n: Integer)

Divides in place, keeping the original unit when it divides evenly and otherwise falling back to the finer unit (years -> months, weeks -> days).

§Panics

Panics if n is zero, or if the period is not divisible by n even after refining the unit (matching QuantLib’s QL_REQUIRE).

Source§

impl FromStr for Period

Source§

fn from_str(s: &str) -> QlResult<Period>

Parses a period string via parse_period, so "6M".parse::<Period>() works.

Source§

type Err = QlError

The associated error which can be returned from parsing.
Source§

impl Mul<Period> for Integer

Source§

type Output = Period

The resulting type after applying the * operator.
Source§

fn mul(self, p: Period) -> Period

Performs the * operation. Read more
Source§

impl Mul<i32> for Period

Source§

type Output = Period

The resulting type after applying the * operator.
Source§

fn mul(self, n: Integer) -> Period

Performs the * operation. Read more
Source§

impl MulAssign<i32> for Period

Source§

fn mul_assign(&mut self, n: Integer)

Performs the *= operation. Read more
Source§

impl Neg for Period

Source§

type Output = Period

The resulting type after applying the - operator.
Source§

fn neg(self) -> Period

Performs the unary - operation. Read more
Source§

impl PartialEq for Period

Source§

fn eq(&self, other: &Period) -> bool

Semantic equality: true only for a decidably-equal pair (an undecidable comparison is not equal).

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Period

Source§

fn partial_cmp(&self, other: &Period) -> Option<Ordering>

Returns None when the comparison is undecidable (see module docs).

1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for Period

Source§

type Output = Period

The resulting type after applying the - operator.
Source§

fn sub(self, p: Period) -> Period

Performs the - operation. Read more
Source§

impl Sub<Period> for Date

Source§

type Output = Date

The resulting type after applying the - operator.
Source§

fn sub(self, p: Period) -> Date

Performs the - operation. Read more
Source§

impl SubAssign for Period

Source§

fn sub_assign(&mut self, p: Period)

Performs the -= operation. Read more
Source§

impl TryFrom<Frequency> for Period

Source§

fn try_from(f: Frequency) -> QlResult<Period>

Builds the canonical period for a frequency (Annual -> 1 Year, Quarterly -> 3 Months, …).

§Errors

Returns an error for OtherFrequency, which names no definite period (matching QuantLib’s QL_FAIL).

Source§

type Error = QlError

The type returned in the event of a conversion error.

Auto Trait Implementations§

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, 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.