eyeball_im_util::vector

Struct Tail

Source
pub struct Tail<S, L>{ /* private fields */ }
Expand description

A VectorDiff stream adapter that presents a reversed limited view of the underlying ObservableVectors items. The view starts from the last index of the ObservableVector, i.e. it starts from the end. This is the opposite of Head, which starts from 0.

For example, let S be a Stream<Item = VectorDiff>. The Vector represented by S can have any length, but one may want to virtually limit this Vector from the end to a certain size. Then this Tail adapter is appropriate.

An internal buffered vector is kept so that the adapter knows which values can be added when the limit is increased, 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 a limit 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().tail(3);

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

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

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

// Append multiple other values.
ob.append(vector!['e', 'f']);
// We get three `VectorDiff`s!
assert_next_eq!(sub, VectorDiff::PopFront);
assert_next_eq!(sub, VectorDiff::PopFront);
assert_next_eq!(sub, VectorDiff::Append { values: vector!['e', 'f'] });

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

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

Implementations§

Source§

impl<S> Tail<S, EmptyLimitStream>

Source

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

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

Returns the truncated initial values as well as a stream of updates that ensure that the resulting vector never exceeds the given limit.

Source§

impl<S, L> Tail<S, L>
where S: Stream, S::Item: VectorDiffContainer, L: Stream<Item = usize>,

Source

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

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

This is equivalent to dynamic_with_initial_limit where the initial_limit is 0, except that it doesn’t return the limited vector as it would be empty anyways.

Note that the returned Tail won’t produce anything until the first limit is produced by the limit stream.

Source

pub fn dynamic_with_initial_limit( initial_values: Vector<VectorDiffContainerStreamElement<S>>, inner_stream: S, initial_limit: usize, limit_stream: L, ) -> (Vector<VectorDiffContainerStreamElement<S>>, Self)

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

Trait Implementations§

Source§

impl<S, L> Stream for Tail<S, L>
where S: Stream, S::Item: VectorDiffContainer, L: 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, L> Unpin for Tail<S, L>
where PinnedFieldsOf<__Origin<'__pin, S, L>>: Unpin, S: Stream, S::Item: VectorDiffContainer,

Source§

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

Auto Trait Implementations§

§

impl<S, L> Freeze for Tail<S, L>
where <S as Stream>::Item: Sized, S: Freeze, L: Freeze, <<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::TailBuf: Freeze,

§

impl<S, L> RefUnwindSafe for Tail<S, L>
where <S as Stream>::Item: Sized, S: RefUnwindSafe, L: RefUnwindSafe, <<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::TailBuf: RefUnwindSafe, <<S as Stream>::Item as VectorDiffContainer>::Element: RefUnwindSafe,

§

impl<S, L> Send for Tail<S, L>
where <S as Stream>::Item: Sized, S: Send, L: Send, <<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::TailBuf: Send, <<S as Stream>::Item as VectorDiffContainer>::Element: Send + Sync,

§

impl<S, L> Sync for Tail<S, L>
where <S as Stream>::Item: Sized, S: Sync, L: Sync, <<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::TailBuf: Sync, <<S as Stream>::Item as VectorDiffContainer>::Element: Sync + Send,

§

impl<S, L> UnwindSafe for Tail<S, L>
where <S as Stream>::Item: Sized, S: UnwindSafe, L: UnwindSafe, <<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::TailBuf: 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