pub struct Timing {
    pub start: i32,
    pub end: i32,
}
Expand description

A start-inclusive, end-exclusive i32 range (like Range<i32>) that is copyable, and implements several utility methods.

Fields§

§start: i32

The inclusive start of this interval.

§end: i32

The exclusive end of this interval.

Implementations§

source§

impl Timing

source

pub fn len(&self) -> i32

Returns the length of this timing (self.end - self.start).

source

pub fn divide_into(&self, size: i32) -> Vec<Timing>

Splits this timing into sequentual pieces of a given size. Returns the resulting Vec.

let split = Timing::from(0..10).divide_into(5);
assert_eq!(split[0], Timing::from(0..5));
assert_eq!(split[1], Timing::from(5..10));
source

pub fn shifted_by(&self, amount: i32) -> Timing

Returns a new Timing with start/end shifted by the given amount.

assert_eq!(Timing::from(0..10).shifted_by(10), Timing::from(10..20))
source

pub fn start_shifted_by(&self, amount: i32) -> Timing

Returns a new Timing with the start shifted by the given amount.

assert_eq!(Timing::from(0..10).start_shifted_by(5), Timing::from(5..10))
source

pub fn end_shifted_by(&self, amount: i32) -> Timing

Returns a new Timing with the end shifted by the given amount.

assert_eq!(Timing::from(0..10).end_shifted_by(-5), Timing::from(0..5))
source

pub fn contains(&self, item: &i32) -> bool

Checks if a particular &i32 is contained in this Timing.

assert_eq!(Timing::from(1..10).contains(&1), true);
assert_eq!(Timing::from(1..10).contains(&10), false);
source

pub fn is_empty(&self) -> bool

Checks if this Timing is empty (including negative).

assert_eq!(Timing::from(1..1).is_empty(), true);
assert_eq!(Timing::from(1..0).is_empty(), true);
assert_eq!(Timing::from(1..2).is_empty(), false);
source

pub fn is_before(&self, other: &impl RangeBounds<i32>) -> bool

Checks if this Timing is before some other Timing (or other RangeBounds<i32>).

assert_eq!(Timing::from(0..1).is_before(&Timing::from(1..2)), true);
assert_eq!(Timing::from(1..2).is_before(&Timing::from(0..1)), false);
source

pub fn is_after(&self, other: &impl RangeBounds<i32>) -> bool

Checks if this Timing is after some other Timing (or other RangeBounds<i32>).

assert_eq!(Timing::from(0..1).is_after(&Timing::from(1..2)), false);
assert_eq!(Timing::from(1..2).is_after(&Timing::from(0..1)), true);
source

pub fn is_disjoint_from(&self, other: &impl RangeBounds<i32>) -> bool

Checks if this Timing does not overlap with another Timing (or other RangeBounds<i32>).

assert_eq!(Timing::from(0..2).is_disjoint_from(&Timing::from(2..3)), true);
assert_eq!(Timing::from(0..2).is_disjoint_from(&Timing::from(1..3)), false);
source

pub fn intersects(&self, other: &impl RangeBounds<i32>) -> bool

Checks if this Timing overlaps with another Timing (or other RangeBounds<i32>).

assert_eq!(Timing::from(0..2).intersects(&Timing::from(1..3)), true);
assert_eq!(Timing::from(0..2).intersects(&Timing::from(2..3)), false);
source

pub fn contains_range(&self, other: &impl RangeBounds<i32>) -> bool

Checks if this Timing contains another Timing (or other RangeBounds<i32>).

assert_eq!(Timing::from(0..2).contains_range(&Timing::from(0..1)), true);
assert_eq!(Timing::from(0..2).contains_range(&Timing::from(1..3)), false);
source

pub fn is_contained_by(&self, other: &impl RangeBounds<i32>) -> bool

Checks if this Timing is contained by another Timing (or other RangeBounds<i32>).

assert_eq!(Timing::from(0..2).is_contained_by(&Timing::from(0..3)), true);
assert_eq!(Timing::from(0..2).is_contained_by(&Timing::from(0..1)), false);
source

pub fn begins_within(&self, other: &impl RangeBounds<i32>) -> bool

Checks if this Timing begins within another Timing (or other RangeBounds<i32>).

assert_eq!(Timing::from(0..1).begins_within(&Timing::from(0..2)), true);
assert_eq!(Timing::from(0..1).begins_within(&Timing::from(1..2)), false);
source

pub fn ends_within(&self, other: &impl RangeBounds<i32>) -> bool

Checks if this Timing ends within another Timing (or other RangeBounds<i32>).

assert_eq!(Timing::from(0..2).ends_within(&Timing::from(0..2)), true);
assert_eq!(Timing::from(0..2).ends_within(&Timing::from(0..1)), false);

Trait Implementations§

source§

impl Clone for Timing

source§

fn clone(&self) -> Timing

Returns a copy 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 Timing

source§

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

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

impl From<&Range<i32>> for Timing

source§

fn from(value: &Range<i32>) -> Self

Converts to this type from the input type.
source§

impl From<&Timing> for Range<i32>

source§

fn from(value: &Timing) -> Self

Converts to this type from the input type.
source§

impl From<&Timing> for Timing

source§

fn from(value: &Timing) -> Self

Converts to this type from the input type.
source§

impl From<Range<i32>> for Timing

source§

fn from(value: Range<i32>) -> Self

Converts to this type from the input type.
source§

impl From<Timing> for Range<i32>

source§

fn from(value: Timing) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Timing

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl RangeBounds<i32> for Timing

source§

fn start_bound(&self) -> Bound<&i32>

Start index bound. Read more
source§

fn end_bound(&self) -> Bound<&i32>

End index bound. Read more
1.35.0 · source§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
source§

impl Copy for Timing

source§

impl Eq for Timing

source§

impl StructuralPartialEq for Timing

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> 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, R> RangeOps<T> for R
where T: PartialOrd, R: RangeBounds<T>,

source§

fn is_empty(&self) -> bool

Checks if an interval is empty.
source§

fn is_before(&self, other: &impl RangeBounds<T>) -> bool

Checks if this interval ends before the start of another.
source§

fn is_after(&self, other: &impl RangeBounds<T>) -> bool

Checks if this interval starts after the end of another.
source§

fn is_disjoint_from(&self, other: &impl RangeBounds<T>) -> bool

Checks if an interval has no overlap with another.
source§

fn intersects(&self, other: &impl RangeBounds<T>) -> bool

Checks if this interval has some overlap with another.
source§

fn contains_range(&self, other: &impl RangeBounds<T>) -> bool

Checks if this interval contains another.
source§

fn is_contained_by(&self, other: &impl RangeBounds<T>) -> bool

Checks if this interval is contained by another.
source§

fn begins_within(&self, other: &impl RangeBounds<T>) -> bool

Checks if this interval starts within another.
source§

fn ends_within(&self, other: &impl RangeBounds<T>) -> bool

Checks if this interval ends within another.
source§

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

§

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

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V