Struct TimeSpan

Source
pub struct TimeSpan {
    pub start: TimePoint,
    pub end: TimePoint,
}
Expand description

Represents a time span from “start” (included) to “end” (excluded).

The constructors will ensure “start <= end”, this condition will hold at any given time.

Fields§

§start: TimePoint

The first time point of the time span (inclusive)

§end: TimePoint

The last time point of the time span (excluded)

Implementations§

Source§

impl TimeSpan

Source

pub fn new(start: TimePoint, end: TimePoint) -> TimeSpan

Create a new TimeSpan with start and end.

§Examples
use alass_core::{TimeSpan, TimePoint};

let t0 = TimePoint::from(0);
let t10 = TimePoint::from(10);

let ts = TimeSpan::new(t0, t10);
§Panics

This function asserts that start is less or equal end.

use alass_core::{TimeSpan, TimePoint};

let t0 = TimePoint::from(0);
let t10 = TimePoint::from(10);

// this will case a panic
let ts = TimeSpan::new(t10, t0);
Source

pub fn new_safe(start: TimePoint, end: TimePoint) -> TimeSpan

Create a new TimeSpan with start and end. This function will not panic on end < start, but swap the values before calling TimeSpan::new().

§Examples
use alass_core::{TimeSpan, TimePoint};

let t0 = TimePoint::from(0);
let t10 = TimePoint::from(10);

let ts = TimeSpan::new_safe(t10, t0);
assert!(ts.start() == t0 && ts.end() == t10);
Source

pub fn new_copy_with_end(self, new_end: TimePoint) -> TimeSpan

Mutates a TimeSpans end.

§Panics

Will panic if new_end is less than current start.

Source

pub fn len(self) -> TimeDelta

Returns the length of the TimeSpan.

len() is zero, if and only if start is end.

Source

pub fn is_empty(self) -> bool

Returns true if start == end.

Source

pub fn start(self) -> TimePoint

Returns the start point of the TimeSpan.

Source

pub fn end(self) -> TimePoint

Returns the end point of the TimeSpan.

Source

pub fn half(self) -> TimePoint

Returns one (of the possibly two) points in the center of the TimeSpan.

Source

pub fn contains(self, other: TimeSpan) -> bool

Returns true if self contains TimeSpan other.

§Examples
use alass_core::{TimeSpan, TimePoint};
Source

pub fn fast_distance_to(self, other: TimeSpan) -> TimeDelta

Returns the smallest difference between two TimeSpans.

use alass_core::{TimeSpan, TimePoint, TimeDelta};

let p = TimePoint::from(0);
let d = TimeDelta::one();

let ts1 = TimeSpan::new(p, p + 10 * d);
let ts4 = TimeSpan::new(p + 20 * d, p + 100 * d);

assert!(TimeSpan::fast_distance_to(ts1, ts1) == 0 * d);
assert!(TimeSpan::fast_distance_to(ts1, ts4) == 10 * d);
assert!(TimeSpan::fast_distance_to(ts4, ts1) == 10 * d);
assert!(TimeSpan::fast_distance_to(ts4, ts4) == 0 * d);
Source

pub fn get_overlapping_length(self, other: TimeSpan) -> TimeDelta

Returns the smallest difference between two TimeSpans.

Source

pub fn scaled(self, scaling_factor: f64) -> TimeSpan

Scale start and end time point to zero by scaling_factor.

Source

pub fn cmp_start(self, other: TimeSpan) -> Ordering

Compares two TimeSpans by their start timepoint.

Source

pub fn cmp_end(self, other: TimeSpan) -> Ordering

Compares two TimeSpans by their end timepoint.

Trait Implementations§

Source§

impl Add<TimeDelta> for TimeSpan

Source§

type Output = TimeSpan

The resulting type after applying the + operator.
Source§

fn add(self, rhs: TimeDelta) -> TimeSpan

Performs the + operation. Read more
Source§

impl Clone for TimeSpan

Source§

fn clone(&self) -> TimeSpan

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TimeSpan

Source§

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

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

impl Hash for TimeSpan

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TimeSpan

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for TimeSpan

Source§

impl Eq for TimeSpan

Source§

impl StructuralPartialEq for TimeSpan

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