Struct Timing

Source
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<O>(&self, amount: O) -> Timing
where O: EndpointOffsets,

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

May also accept a (i32, i32) tuple representing different start/end shifts.

assert_eq!(Timing::from(1..10).shifted_by((-1, 1)), Timing::from(0..11))
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 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 Timing

Source§

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

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

impl<'de> Deserialize<'de> for Timing

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Timing, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&Range<i32>> for Timing

Source§

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

Converts to this type from the input type.
Source§

impl<'a, T> From<&SegmentRef<'a, T>> for Timing
where T: Element,

Source§

fn from(value: &SegmentRef<'a, T>) -> Timing

Converts to this type from the input type.
Source§

impl From<&Subdivision> for Timing

Source§

fn from(value: &Subdivision) -> Timing

Converts to this type from the input type.
Source§

impl From<&Timing> for Timing

Source§

fn from(value: &Timing) -> Timing

Converts to this type from the input type.
Source§

impl From<Range<i32>> for Timing

Source§

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

Converts to this type from the input type.
Source§

impl<'a, T> From<SegmentRef<'a, T>> for Timing
where T: Element,

Source§

fn from(value: SegmentRef<'a, T>) -> Timing

Converts to this type from the input type.
Source§

impl From<Subdivision> for Timing

Source§

fn from(value: Subdivision) -> Timing

Converts to this type from the input type.
Source§

impl PartialEq for Timing

Source§

fn eq(&self, other: &Timing) -> 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 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§

fn is_empty(&self) -> bool
where T: PartialOrd,

🔬This is a nightly-only experimental API. (range_bounds_is_empty)
Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more
Source§

impl Serialize for Timing

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

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

impl Copy for Timing

Source§

impl Eq for Timing

Source§

impl StructuralPartialEq for Timing

Auto Trait Implementations§

§

impl Freeze for Timing

§

impl RefUnwindSafe for Timing

§

impl Send for Timing

§

impl Sync for Timing

§

impl Unpin for Timing

§

impl UnwindSafe for Timing

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

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,