Struct lset::Span

source · []
#[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

Create a new span

Example
let span = lset::Span::new(5, 10);
assert_eq!(span.start, 5);
assert_eq!(span.count, 10);

Indicates whether the span is empty

Example
use lset::*;
assert!(Span::from(2..2).is_empty());
assert!(!Span::from(2..3).is_empty());

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

Grows the line by the size of the operand

Example
let before = lset::Span::new(5, 10);
let after = before + 5;
assert_eq!(after.start, 5);
assert_eq!(after.count, 15);

The resulting type after applying the + operator.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

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

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts a Line into a Span

Example
use lset::*;
assert_eq!(Span::new(5, 10), Span::from(Line::new(5, 15)));
assert_eq!(Span::new(5, 10), (Line::new(5, 15)).into());

Converts a Range into a Span

Example
use lset::*;
assert_eq!(Span::new(5, 10), Span::from(5..15));
assert_eq!(Span::new(5, 10), (5..15).into());

Converts a Span into a Line

Example
use lset::*;
assert_eq!(Line::new(5, 10), Line::from(Span::new(5, 5)));
assert_eq!(Line::new(5, 10), Span::new(5, 5).into());

Converts a Span into a Range

Example
use lset::*;
assert_eq!(5..15, std::ops::Range::from(Span::new(5, 10)));
assert_eq!(5..15, Span::new(5, 10).into());

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Shifts the line downwards without changing size

Example
let before = lset::Span::new(5, 10);
let after = before << 5;
assert_eq!(after.start, 0);
assert_eq!(after.count, 10);

The resulting type after applying the << operator.

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

Shifts the line upwards without changing size

Example
let before = lset::Span::new(5, 10);
let after = before >> 5;
assert_eq!(after.start, 10);
assert_eq!(after.count, 10);

The resulting type after applying the >> operator.

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

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

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

Shrinks the line by the size of the operand

Example
let before = lset::Span::new(5, 10);
let after = before - 5;
assert_eq!(after.start, 5);
assert_eq!(after.count, 5);

The resulting type after applying the - operator.

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.