pub struct Skip<S, C>{ /* private fields */ }
Expand description
A VectorDiff
stream adapter that presents a limited view of the
underlying ObservableVector
s 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>
impl<S> Skip<S, EmptyCountStream>
Sourcepub fn new(
initial_values: Vector<VectorDiffContainerStreamElement<S>>,
inner_stream: S,
count: usize,
) -> (Vector<VectorDiffContainerStreamElement<S>>, Self)
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>
impl<S, C> Skip<S, C>
Sourcepub fn dynamic(
initial_values: Vector<VectorDiffContainerStreamElement<S>>,
inner_stream: S,
count_stream: C,
) -> Self
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.
Sourcepub fn dynamic_with_initial_count(
initial_values: Vector<VectorDiffContainerStreamElement<S>>,
inner_stream: S,
initial_count: usize,
count_stream: C,
) -> (Vector<VectorDiffContainerStreamElement<S>>, Self)
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.