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
impl Timing
Sourcepub fn divide_into(&self, size: i32) -> Vec<Timing>
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));
Sourcepub fn shifted_by<O>(&self, amount: O) -> Timingwhere
O: EndpointOffsets,
pub fn shifted_by<O>(&self, amount: O) -> Timingwhere
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))
Sourcepub fn start_shifted_by(&self, amount: i32) -> Timing
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))
Sourcepub fn end_shifted_by(&self, amount: i32) -> Timing
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))
Sourcepub fn contains(&self, item: &i32) -> bool
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);
Sourcepub fn is_empty(&self) -> bool
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);
Sourcepub fn is_before(&self, other: &impl RangeBounds<i32>) -> bool
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);
Sourcepub fn is_after(&self, other: &impl RangeBounds<i32>) -> bool
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);
Sourcepub fn is_disjoint_from(&self, other: &impl RangeBounds<i32>) -> bool
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);
Sourcepub fn intersects(&self, other: &impl RangeBounds<i32>) -> bool
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);
Sourcepub fn contains_range(&self, other: &impl RangeBounds<i32>) -> bool
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);
Sourcepub fn is_contained_by(&self, other: &impl RangeBounds<i32>) -> bool
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);
Sourcepub fn begins_within(&self, other: &impl RangeBounds<i32>) -> bool
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);
Sourcepub fn ends_within(&self, other: &impl RangeBounds<i32>) -> bool
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);