Skip to main content

IntervalsSingle

Struct IntervalsSingle 

Source
pub struct IntervalsSingle<E, V> { /* private fields */ }
Expand description

An Intervals stream containing a single Interval.

This is the simplest way to lift an Interval into the Intervals trait so it can participate in composition (&, |, etc.).

Implementations§

Source§

impl<E, V> IntervalsSingle<E, V>

Source

pub fn new(v: Interval<E, V>) -> Self

Wrap a single Interval.

Examples found in repository?
examples/shift.rs (line 10)
7fn main() {
8    // [1, 4)
9    let i = Interval::new(EndpointOC::Closed(1), EndpointOC::Open(4), ());
10    let is = IntervalsSingle::new(i);
11
12    // Shift everything by +5 → [6, 9)
13    for iv in IntervalShift::new(is, 5).into_iter() {
14        println!("{:?}", iv);
15    }
16}
More examples
Hide additional examples
examples/union.rs (line 16)
10fn main() {
11    // [1, 3] tagged "A"
12    let ia = Interval::new(EndpointOC::Closed(1), EndpointOC::Closed(3), "A");
13    // (2, 4) tagged "B"
14    let ib = Interval::new(EndpointOC::Open(2), EndpointOC::Open(4), "B");
15
16    let isa = IntervalsSingle::new(ia);
17    let isb = IntervalsSingle::new(ib);
18
19    // Union: [1,2] -> (Some("A"), None), (2,3] -> (Some("A"), Some("B")), (3,4) -> (None, Some("B"))
20    for iv in or(isa, isb).into_iter() {
21        println!("{:?}", iv);
22    }
23}
examples/intersection.rs (line 13)
7fn main() {
8    // [1, 3] tagged "A"
9    let ia = Interval::new(EndpointOC::Closed(1), EndpointOC::Closed(3), "A");
10    // (2, 4) tagged "B"
11    let ib = Interval::new(EndpointOC::Open(2), EndpointOC::Open(4), "B");
12
13    let isa = IntervalsSingle::new(ia);
14    let isb = IntervalsSingle::new(ib);
15
16    // Intersection: (2, 3] tagged ("A", "B")
17    let result = and(isa, isb).into_iter().collect::<Vec<_>>();
18
19    for iv in &result {
20        println!("{:?}", iv);
21    }
22
23    assert_eq!(result.len(), 1);
24    assert_eq!(
25        result[0],
26        Interval::new(EndpointOC::Open(2), EndpointOC::Closed(3), ("A", "B"))
27    );
28}

Trait Implementations§

Source§

impl<T, V, Ic> BitAnd<Ic> for IntervalsSingle<T, V>
where Self: Intervals, Ic: Intervals<Endpoint = <Self as Intervals>::Endpoint>,

Available on crate feature operators only.
Source§

type Output = IntervalsWrap<IntervalsAnd<IntervalsSingle<T, V>, Ic>>

The resulting type after applying the & operator.
Source§

fn bitand(self, c: Ic) -> Self::Output

Performs the & operation. Read more
Source§

impl<T, V, Ic> BitOr<Ic> for IntervalsSingle<T, V>

Available on crate feature operators only.
Source§

type Output = IntervalsWrap<IntervalsOr<IntervalsSingle<T, V>, Ic>>

The resulting type after applying the | operator.
Source§

fn bitor(self, c: Ic) -> Self::Output

Performs the | operation. Read more
Source§

impl<E, V> Intervals for IntervalsSingle<E, V>
where E: Clone + EndpointToggle, LeftT<E>: Ord, V: Copy,

Source§

type Endpoint = E

The endpoint flavor — typically EndpointOC or EndpointSymmetric.
Source§

type Value = V

The value attached to each interval.
Source§

fn head( &mut self, pos: Option<LeftT<Self::Endpoint>>, ) -> Option<Interval<Self::Endpoint, Self::Value>>

Return the next interval whose right endpoint is greater than pos. Read more

Auto Trait Implementations§

§

impl<E, V> Freeze for IntervalsSingle<E, V>
where V: Freeze, E: Freeze,

§

impl<E, V> RefUnwindSafe for IntervalsSingle<E, V>

§

impl<E, V> Send for IntervalsSingle<E, V>
where V: Send, E: Send,

§

impl<E, V> Sync for IntervalsSingle<E, V>
where V: Sync, E: Sync,

§

impl<E, V> Unpin for IntervalsSingle<E, V>
where V: Unpin, E: Unpin,

§

impl<E, V> UnsafeUnpin for IntervalsSingle<E, V>
where V: UnsafeUnpin, E: UnsafeUnpin,

§

impl<E, V> UnwindSafe for IntervalsSingle<E, V>
where V: UnwindSafe, E: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<I> InIntervalsMapEndpoints for I
where I: Intervals,

Source§

fn map_endpoints<F, G, Tin, Tout>( self, forward: F, inverse: G, ) -> IntervalsEndpointMap<I, F, G, Tin, Tout>
where F: Fn(Tin) -> Tout, G: Fn(Tout) -> Tin,

Transform endpoint values through the forward / inverse pair. Read more
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, 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.