eyeball_im_util::vector

Struct Skip

Source
pub struct Skip<S, C>{ /* private fields */ }
Expand description

A VectorDiff stream adapter that presents a limited view of the underlying ObservableVectors items. The view starts after count number of values are skipped, until the end. It must not be confused with Tail where Tail keeps the last values, while Skip skips the first values.

For example, let S be a Stream<Item = VectorDiff>. The Vector represented by S can have any length, but one may want to virtually skip the first count values. Then this Skip adapter is appropriate.

An internal buffered vector is kept so that the adapter knows which values can be added when the index is decreased, or when values are removed and new values must be inserted. This fact is important if the items of the Vector have a non-negligible size.

It’s okay to have an index larger than the length of the observed Vector.

§Examples

use eyeball_im::{ObservableVector, VectorDiff};
use eyeball_im_util::vector::VectorObserverExt;
use imbl::vector;
use stream_assert::{assert_closed, assert_next_eq, assert_pending};

// Our vector.
let mut ob = ObservableVector::<char>::new();
let (values, mut sub) = ob.subscribe().skip(3);

assert!(values.is_empty());
assert_pending!(sub);

// Append multiple values.
ob.append(vector!['a', 'b', 'c', 'd', 'e']);
// We get a `VectorDiff::Append` with the latest 2 values because the
// first 3 values have been skipped!
assert_next_eq!(sub, VectorDiff::Append { values: vector!['d', 'e'] });

// Let's recap what we have. `ob` is our `ObservableVector`,
// `sub` is the “limited view” of `ob`:
// | `ob`  | a b c d e |
// | `sub` | _ _ _ d e |
// “_” means the item has been skipped.

// Append multiple values.
ob.append(vector!['f', 'g']);
// We get a single `VectorDiff`.
assert_next_eq!(sub, VectorDiff::Append { values: vector!['f', 'g'] });

// Let's recap what we have:
// | `ob`  | a b c d e f g |
// | `sub` | _ _ _ d e f g |
//                     ^^^
//                     |
//                     `VectorDiff::Append { .. }`

// Insert a single value.
ob.insert(1, 'h');
// We get a single `VectorDiff::PushFront`. Indeed, `h` is inserted at
// index 1, so every value after that is shifted to the right, thus `c`
// “enters the view” via a `PushFront`.
assert_next_eq!(sub, VectorDiff::PushFront { value: 'c' });

// Let's recap what we have:
// | `ob`  | a h b c d e f g |
// | `sub` | _ _ _ c d e f g |
//                 ^
//                 |
//                 `VectorDiff::PushFront { .. }`

assert_pending!(sub);
drop(ob);
assert_closed!(sub);

Implementations§

Source§

impl<S> Skip<S, EmptyCountStream>

Source

pub fn new( initial_values: Vector<VectorDiffContainerStreamElement<S>>, inner_stream: S, count: usize, ) -> (Vector<VectorDiffContainerStreamElement<S>>, Self)

Create a new Skip with the given (unlimited) initial values, stream of VectorDiff updates for those values, and a fixed count.

Returns the initial values as well as a stream of updates that ensure that the resulting vector never includes the first count items.

Source§

impl<S, C> Skip<S, C>
where S: Stream, S::Item: VectorDiffContainer, C: Stream<Item = usize>,

Source

pub fn dynamic( initial_values: Vector<VectorDiffContainerStreamElement<S>>, inner_stream: S, count_stream: C, ) -> Self

Create a new Skip with the given (unlimited) initial values, stream of VectorDiff updates for those values, and a stream of indices.

This is equivalent to dynamic_with_initial_count where the initial_count is usize::MAX, except that it doesn’t return the limited vector as it would be empty anyways.

Note that the returned Skip won’t produce anything until the first count is produced by the index stream.

Source

pub fn dynamic_with_initial_count( initial_values: Vector<VectorDiffContainerStreamElement<S>>, inner_stream: S, initial_count: usize, count_stream: C, ) -> (Vector<VectorDiffContainerStreamElement<S>>, Self)

Create a new Skip with the given (unlimited) initial values, stream of VectorDiff updates for those values, and an initial count as well as a stream of new count values.

Trait Implementations§

Source§

impl<S, C> Stream for Skip<S, C>
where S: Stream, S::Item: VectorDiffContainer, C: Stream<Item = usize>,

Source§

type Item = <S as Stream>::Item

Values yielded by the stream.
Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
Source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more
Source§

impl<'__pin, S, C> Unpin for Skip<S, C>
where PinnedFieldsOf<__Origin<'__pin, S, C>>: Unpin, S: Stream, S::Item: VectorDiffContainer,

Source§

impl<S, C> VectorObserver<<<S as Stream>::Item as VectorDiffContainer>::Element> for Skip<S, C>
where S: Stream, S::Item: VectorDiffContainer, C: Stream<Item = usize>,

Auto Trait Implementations§

§

impl<S, C> Freeze for Skip<S, C>
where <S as Stream>::Item: Sized, S: Freeze, C: Freeze, <<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::SkipBuf: Freeze,

§

impl<S, C> RefUnwindSafe for Skip<S, C>
where <S as Stream>::Item: Sized, S: RefUnwindSafe, C: RefUnwindSafe, <<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::SkipBuf: RefUnwindSafe, <<S as Stream>::Item as VectorDiffContainer>::Element: RefUnwindSafe,

§

impl<S, C> Send for Skip<S, C>
where <S as Stream>::Item: Sized, S: Send, C: Send, <<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::SkipBuf: Send, <<S as Stream>::Item as VectorDiffContainer>::Element: Send + Sync,

§

impl<S, C> Sync for Skip<S, C>
where <S as Stream>::Item: Sized, S: Sync, C: Sync, <<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::SkipBuf: Sync, <<S as Stream>::Item as VectorDiffContainer>::Element: Sync + Send,

§

impl<S, C> UnwindSafe for Skip<S, C>
where <S as Stream>::Item: Sized, S: UnwindSafe, C: UnwindSafe, <<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::SkipBuf: UnwindSafe, <<S as Stream>::Item as VectorDiffContainer>::Element: UnwindSafe + RefUnwindSafe,

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. 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.
Source§

impl<S, T, E> TryStream for S
where S: Stream<Item = Result<T, E>> + ?Sized,

Source§

type Ok = T

The type of successful values yielded by this future
Source§

type Error = E

The type of failures yielded by this future
Source§

fn try_poll_next( self: Pin<&mut S>, cx: &mut Context<'_>, ) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

Poll this TryStream as if it were a Stream. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more