#[repr(C)]pub struct Span<T, U = T> {
pub start: T,
pub count: U,
}
Expand description
Expresses a linear set by its start element and number of elements.
This type is fully isomorphic with core::ops::Range
and Line
. However,
unlike core::ops::Range
, this type is not an iterator and therefore can
implement Copy
.
Fields
start: T
The start element
count: U
The number of elments
Implementations
sourceimpl<T, U> Span<T, U>
impl<T, U> Span<T, U>
sourceimpl<T, U> Span<T, U> where
Span<T, U>: Into<Line<T>> + From<Line<T>>,
T: PartialOrd,
impl<T, U> Span<T, U> where
Span<T, U>: Into<Line<T>> + From<Line<T>>,
T: PartialOrd,
sourcepub fn intersection(self, other: Self) -> Option<Self>
pub fn intersection(self, other: Self) -> Option<Self>
Returns the intersection between the sets, if any.
use lset::*;
let a = Span::new(0, 5);
let b = Span::new(2, 5);
let c = Span::new(5, 5);
assert_eq!(a.intersection(b), Some(Span::new(2, 3)));
assert_eq!(b.intersection(c), Some(Span::new(5, 2)));
assert_eq!(a.intersection(a), Some(a));
assert_eq!(b.intersection(b), Some(b));
assert_eq!(c.intersection(c), Some(c));
assert_eq!(a.intersection(c), None);
Trait Implementations
sourceimpl<T: AddAssign<T>> AddAssign<T> for Span<T>
impl<T: AddAssign<T>> AddAssign<T> for Span<T>
sourcefn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Grows the line by the size of the operand
Example
let mut span = lset::Span::new(5, 10);
span += 5;
assert_eq!(span.start, 5);
assert_eq!(span.count, 15);
sourceimpl<T, U> Contains<Span<T, U>> for Span<T, U> where
Self: Into<Line<T>> + Clone,
T: PartialOrd,
impl<T, U> Contains<Span<T, U>> for Span<T, U> where
Self: Into<Line<T>> + Clone,
T: PartialOrd,
sourcefn contains(&self, value: &Self) -> bool
fn contains(&self, value: &Self) -> bool
Indicates whether the span contains another span
Example
use lset::*;
assert!(Span::from(4..8).contains(&Span::from(5..7)));
assert!(Span::from(4..8).contains(&Span::from(4..7)));
assert!(Span::from(4..8).contains(&Span::from(5..8)));
assert!(Span::from(4..8).contains(&Span::from(4..8)));
assert!(!Span::from(4..8).contains(&Span::from(3..8)));
assert!(!Span::from(4..8).contains(&Span::from(4..9)));
assert!(!Span::from(4..8).contains(&Span::from(3..9)));
assert!(!Span::from(4..8).contains(&Span::from(2..10)));
assert!(!Span::from(4..8).contains(&Span::from(6..5)));
assert!(!Span::from(7..3).contains(&Span::from(5..6)));
sourceimpl<T, U> Contains<T> for Span<T, U> where
Self: Into<Line<T>> + Clone,
Line<T>: Contains<T>,
impl<T, U> Contains<T> for Span<T, U> where
Self: Into<Line<T>> + Clone,
Line<T>: Contains<T>,
sourcefn contains(&self, value: &T) -> bool
fn contains(&self, value: &T) -> bool
Indicates whether the span contains a point
Example
use lset::*;
assert!(!Span::from(2..3).contains(&1));
assert!(Span::from(2..3).contains(&2));
assert!(!Span::from(2..3).contains(&3));
assert!(!Span::from(3..2).contains(&1));
assert!(!Span::from(3..2).contains(&2));
assert!(!Span::from(3..2).contains(&3));
sourceimpl<T: PartialEq, U: PartialEq> PartialOrd<Span<T, U>> for Span<T, U> where
Span<T, U>: Copy + Into<Line<T>>,
Line<T>: PartialOrd,
impl<T: PartialEq, U: PartialEq> PartialOrd<Span<T, U>> for Span<T, U> where
Span<T, U>: Copy + Into<Line<T>>,
Line<T>: PartialOrd,
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Compares two Span
types.
Example
use lset::*;
assert!(Span::new(5, 5) <= Span::new(5, 5));
assert!(Span::new(5, 5) >= Span::new(5, 5));
assert!(Span::new(5, 5) < Span::new(10, 5));
assert!(Span::new(10, 5) > Span::new(5, 5));
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<T: Copy + SubAssign<T>> ShlAssign<T> for Span<T>
impl<T: Copy + SubAssign<T>> ShlAssign<T> for Span<T>
sourcefn shl_assign(&mut self, rhs: T)
fn shl_assign(&mut self, rhs: T)
Shifts the line downwards without changing size
Example
let mut span = lset::Span::new(5, 10);
span <<= 5;
assert_eq!(span.start, 0);
assert_eq!(span.count, 10);
sourceimpl<T: Copy + AddAssign<T>> ShrAssign<T> for Span<T>
impl<T: Copy + AddAssign<T>> ShrAssign<T> for Span<T>
sourcefn shr_assign(&mut self, rhs: T)
fn shr_assign(&mut self, rhs: T)
Shifts the line upwards without changing size
Example
let mut span = lset::Span::new(5, 10);
span >>= 5;
assert_eq!(span.start, 10);
assert_eq!(span.count, 10);
sourceimpl<T, U> Split<Span<T, U>> for Span<T, U> where
Self: Into<Line<T>>,
Line<T>: Into<Self>,
Line<T>: Split<Line<T>>,
impl<T, U> Split<Span<T, U>> for Span<T, U> where
Self: Into<Line<T>>,
Line<T>: Into<Self>,
Line<T>: Split<Line<T>>,
sourcefn split(self, at: Self) -> Option<(Self, Self)>
fn split(self, at: Self) -> Option<(Self, Self)>
Splits a span by another span
Example
use lset::*;
let span = Span::from(2..5);
assert_eq!(span.split(Span::from(1..4)), None);
assert_eq!(span.split(Span::from(3..6)), None);
assert_eq!(span.split(Span::from(2..2)), None);
assert_eq!(span.split(Span::from(2..3)), Some((Span::from(2..2), Span::from(3..5))));
assert_eq!(span.split(Span::from(3..3)), None);
assert_eq!(span.split(Span::from(3..4)), Some((Span::from(2..3), Span::from(4..5))));
assert_eq!(span.split(Span::from(4..4)), None);
assert_eq!(span.split(Span::from(4..5)), Some((Span::from(2..4), Span::from(5..5))));
assert_eq!(span.split(Span::from(5..5)), None);
assert_eq!(span.split(span), Some((Span::from(2..2), Span::from(5..5))));
sourceimpl<T, U> Split<U> for Span<T, U> where
T: Add<U, Output = T> + Clone,
Line<T>: Split<T> + Into<Self>,
Self: Into<Line<T>>,
impl<T, U> Split<U> for Span<T, U> where
T: Add<U, Output = T> + Clone,
Line<T>: Split<T> + Into<Self>,
Self: Into<Line<T>>,
sourcefn split(self, at: U) -> Option<(Self, Self)>
fn split(self, at: U) -> Option<(Self, Self)>
Splits a span at a offset
Example
use lset::*;
let span = Span::from(2..4);
assert_eq!(span.split(0), Some((Span::from(2..2), span)));
assert_eq!(span.split(1), Some((Span::from(2..3), Span::from(3..4))));
assert_eq!(span.split(2), Some((span, Span::from(4..4))));
assert_eq!(span.split(3), None);
sourceimpl<T: SubAssign<T>> SubAssign<T> for Span<T>
impl<T: SubAssign<T>> SubAssign<T> for Span<T>
sourcefn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
Shrinks the line by the size of the operand
Example
let mut span = lset::Span::new(5, 10);
span -= 5;
assert_eq!(span.start, 5);
assert_eq!(span.count, 5);
impl<T: Copy, U: Copy> Copy for Span<T, U>
impl<T: Eq, U: Eq> Eq for Span<T, U>
impl<T, U> StructuralEq for Span<T, U>
impl<T, U> StructuralPartialEq for Span<T, U>
Auto Trait Implementations
impl<T, U> RefUnwindSafe for Span<T, U> where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for Span<T, U> where
T: Send,
U: Send,
impl<T, U> Sync for Span<T, U> where
T: Sync,
U: Sync,
impl<T, U> Unpin for Span<T, U> where
T: Unpin,
U: Unpin,
impl<T, U> UnwindSafe for Span<T, U> where
T: UnwindSafe,
U: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more