pub struct Span { /* private fields */ }
Expand description
A closed interval of coordinates in one dimension.
Represents the range [start, stop]
.
Implementations§
source§impl Span
impl Span
sourcepub const unsafe fn new_unchecked(start: i64, stop: i64) -> Span
pub const unsafe fn new_unchecked(start: i64, stop: i64) -> Span
sourcepub const fn from_point(x: i64) -> Span
pub const fn from_point(x: i64) -> Span
Creates a span of zero length encompassing the given point.
sourcepub const fn with_start_and_length(start: i64, length: i64) -> Span
pub const fn with_start_and_length(start: i64, length: i64) -> Span
Creates a span of the given length starting from start
.
sourcepub const fn with_stop_and_length(stop: i64, length: i64) -> Span
pub const fn with_stop_and_length(stop: i64, length: i64) -> Span
Creates a span of the given length ending at stop
.
sourcepub const fn expand(self, sign: Sign, amount: i64) -> Span
pub const fn expand(self, sign: Sign, amount: i64) -> Span
Creates a new Span
expanded by amount
in the direction indicated by pos
.
sourcepub const fn expand_all(self, amount: i64) -> Span
pub const fn expand_all(self, amount: i64) -> Span
Creates a new Span
expanded by amount
in both directions.
sourcepub fn dist_to(&self, point: i64) -> i64
pub fn dist_to(&self, point: i64) -> i64
Gets the shortest distance between this span and a point.
§Example
let span = Span::new(10, 20);
assert_eq!(span.dist_to(4), 6);
assert_eq!(span.dist_to(12), 0);
assert_eq!(span.dist_to(27), 7);
sourcepub fn from_center_span(center: i64, span: i64) -> Span
pub fn from_center_span(center: i64, span: i64) -> Span
Creates a new Span
with center center
and length span
.
span
must be a positive, even integer.
§Example
let span = Span::from_center_span(0, 40);
assert_eq!(span, Span::new(-20, 20));
§Panics
Passing an odd span
to this method results in a panic:
let span = Span::from_center_span(0, 25);
Passing a negative span
to this method also results in a panic:
let span = Span::from_center_span(0, -200);
sourcepub fn from_center_span_gridded(center: i64, span: i64, grid: i64) -> Span
pub fn from_center_span_gridded(center: i64, span: i64, grid: i64) -> Span
Creates a new Span
with center center
and length span
and snap the edges to the
grid.
§Example
let span = Span::from_center_span_gridded(0, 40, 5);
assert_eq!(span, Span::new(-20, 20));
let span = Span::from_center_span_gridded(35, 40, 5);
assert_eq!(span, Span::new(15, 55));
§Panics
This function panics if span
is negative, odd, or not an integer multiple of grid
.
sourcepub const fn intersects(&self, other: &Span) -> bool
pub const fn intersects(&self, other: &Span) -> bool
Checks if the span intersects with the Span
other
.
sourcepub fn merge(spans: impl IntoIterator<Item = Span>) -> Span
pub fn merge(spans: impl IntoIterator<Item = Span>) -> Span
Creates a new minimal Span
that contains all of the elements of spans
.
sourcepub fn union(self, other: Span) -> Span
pub fn union(self, other: Span) -> Span
Calculates the smallest interval containing this span and other
.
sourcepub fn union_all<T>(spans: impl Iterator<Item = T>) -> Span
pub fn union_all<T>(spans: impl Iterator<Item = T>) -> Span
Calculates the minimal bounding interval of all spans provided.
§Example
let spans = vec![
Span::new(10, 40),
Span::new(35, 60),
Span::new(20, 30),
Span::new(-10, 5),
];
assert_eq!(Span::union_all(spans.into_iter()), Span::new(-10, 60));
§Panics
This function panics if the provided iterator has no elements.
If your iterator may be empty, consider using Span::union_all_option
.
sourcepub fn union_all_option<T>(spans: impl Iterator<Item = T>) -> Option<Span>
pub fn union_all_option<T>(spans: impl Iterator<Item = T>) -> Option<Span>
Calculates the minimal bounding interval of all Option<Span>
s provided.
All None
elements in the iterator are ignored.
If the iterator has no Some(_)
elements, this function returns None
.
§Example
let spans = vec![
Some(Span::new(10, 40)),
Some(Span::new(35, 60)),
None,
Some(Span::new(20, 30)),
None,
Some(Span::new(-10, 5)),
];
assert_eq!(Span::union_all_option(spans.into_iter()), Some(Span::new(-10, 60)));
sourcepub fn intersection(self, other: Span) -> Option<Span>
pub fn intersection(self, other: Span) -> Option<Span>
Calculates the intersection of this span with other
.
sourcepub fn add_point(self, pos: i64) -> Span
pub fn add_point(self, pos: i64) -> Span
Returns a new Span
representing the union of the current span with the given point.
sourcepub const fn shrink_all(self, amount: i64) -> Span
pub const fn shrink_all(self, amount: i64) -> Span
Shrinks the span by the given amount on all sides.
sourcepub fn dist_to_span(self, other: Span) -> i64
pub fn dist_to_span(self, other: Span) -> i64
The minimum separation between this span and other
.
§Example
let s1 = Span::new(10, 20);
let s2 = Span::new(30, 50);
let s3 = Span::new(25, 40);
assert_eq!(s1.dist_to_span(s2), 10);
assert_eq!(s1.dist_to_span(s3), 5);
assert_eq!(s2.dist_to_span(s3), 0);
assert_eq!(s3.dist_to_span(s3), 0);
sourcepub fn has_integer_center(&self) -> bool
pub fn has_integer_center(&self) -> bool
Returns whether the span’s center is at an integer coordinate.
§Example
let span = Span::new(0, 100);
assert!(span.has_integer_center());
let span = Span::new(0, 99);
assert!(!span.has_integer_center());
Trait Implementations§
source§impl BoundingUnion<Span> for Span
impl BoundingUnion<Span> for Span
source§impl Contains<Span> for Span
impl Contains<Span> for Span
source§fn contains(&self, other: &Span) -> Containment
fn contains(&self, other: &Span) -> Containment
source§fn partially_intersects(&self, other: &T) -> bool
fn partially_intersects(&self, other: &T) -> bool
other
is fully or partially enclosed in this shape.source§impl<'de> Deserialize<'de> for Span
impl<'de> Deserialize<'de> for Span
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Span, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Span, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl FromIterator<Span> for EnumeratedTracks
impl FromIterator<Span> for EnumeratedTracks
source§impl Ord for Span
impl Ord for Span
source§impl PartialEq for Span
impl PartialEq for Span
source§impl PartialOrd for Span
impl PartialOrd for Span
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for Span
impl Serialize for Span
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for Span
impl Eq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations§
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnwindSafe for Span
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> BoundingUnion<Option<T>> for Twhere
T: BoundingUnion<T, Output = T> + Clone,
impl<T> BoundingUnion<Option<T>> for Twhere
T: BoundingUnion<T, Output = T> + Clone,
source§fn bounding_union(
&self,
other: &Option<T>
) -> <T as BoundingUnion<Option<T>>>::Output
fn bounding_union( &self, other: &Option<T> ) -> <T as BoundingUnion<Option<T>>>::Output
other
. Read more§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<T, U> CustomHardwareType<Flipped<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
impl<T, U> CustomHardwareType<Flipped<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
source§fn from_layout_type(other: &Flipped<T>) -> U
fn from_layout_type(other: &Flipped<T>) -> U
source§impl<T, U> CustomHardwareType<InOut<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
impl<T, U> CustomHardwareType<InOut<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
source§fn from_layout_type(other: &InOut<T>) -> U
fn from_layout_type(other: &InOut<T>) -> U
source§impl<T, U> CustomHardwareType<Input<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
impl<T, U> CustomHardwareType<Input<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
source§fn from_layout_type(other: &Input<T>) -> U
fn from_layout_type(other: &Input<T>) -> U
source§impl<T, U> CustomHardwareType<Output<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
impl<T, U> CustomHardwareType<Output<T>> for Uwhere
U: CustomHardwareType<T>,
T: HardwareType,
source§fn from_layout_type(other: &Output<T>) -> U
fn from_layout_type(other: &Output<T>) -> U
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request