pub struct Sort<S>{ /* private fields */ }
Expand description
A VectorDiff
stream adapter that presents a sorted view of the
underlying ObservableVector
items.
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().sort();
assert!(values.is_empty());
assert_pending!(sub);
// Append multiple unsorted values.
ob.append(vector!['d', 'b', 'e']);
// We get a `VectorDiff::Append` with sorted values!
assert_next_eq!(sub, VectorDiff::Append { values: vector!['b', 'd', 'e'] });
// Let's recap what we have. `ob` is our `ObservableVector`,
// `sub` is the “sorted view” / “sorted stream” of `ob`:
// | `ob` | d b e |
// | `sub` | b d e |
// Append multiple other values.
ob.append(vector!['f', 'g', 'a', 'c']);
// We get three `VectorDiff`s!
assert_next_eq!(sub, VectorDiff::PushFront { value: 'a' });
assert_next_eq!(sub, VectorDiff::Insert { index: 2, value: 'c' });
assert_next_eq!(sub, VectorDiff::Append { values: vector!['f', 'g'] });
// Let's recap what we have:
// | `ob` | d b e f g a c |
// | `sub` | a b c d e f g |
// ^ ^ ^^^
// | | |
// | | with `VectorDiff::Append { .. }`
// | with `VectorDiff::Insert { index: 2, .. }`
// with `VectorDiff::PushFront { .. }`
// Technically, `Sort` emits `VectorDiff`s that mimic a sorted `Vector`.
drop(ob);
assert_closed!(sub);
Implementations§
Source§impl<S> Sort<S>
impl<S> Sort<S>
Sourcepub fn new(
initial_values: Vector<VectorDiffContainerStreamElement<S>>,
inner_stream: S,
) -> (Vector<VectorDiffContainerStreamElement<S>>, Self)
pub fn new( initial_values: Vector<VectorDiffContainerStreamElement<S>>, inner_stream: S, ) -> (Vector<VectorDiffContainerStreamElement<S>>, Self)
Create a new Sort
with the given (unsorted) initial values and stream
of VectorDiff
updates for those values.
Trait Implementations§
Source§impl<S> Stream for Sort<S>
impl<S> Stream for Sort<S>
impl<'__pin, S> Unpin for Sort<S>
Auto Trait Implementations§
impl<S> Freeze for Sort<S>
impl<S> RefUnwindSafe for Sort<S>where
<S as Stream>::Item: Sized,
S: RefUnwindSafe,
<<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::SortBuf: RefUnwindSafe,
<<S as Stream>::Item as VectorDiffContainer>::Element: RefUnwindSafe,
impl<S> Send for Sort<S>
impl<S> Sync for Sort<S>
impl<S> UnwindSafe for Sort<S>where
<S as Stream>::Item: Sized,
S: UnwindSafe,
<<S as Stream>::Item as VectorDiffContainerOps<<<S as Stream>::Item as VectorDiffContainer>::Element>>::SortBuf: UnwindSafe,
<<S as Stream>::Item as VectorDiffContainer>::Element: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more