Skip to main content

LocalBoxFlow

Struct LocalBoxFlow 

Source
pub struct LocalBoxFlow<T> { /* private fields */ }
Expand description

A type-erased Flow confined to one thread, for flows that capture Rc or other thread-bound values.

Trait Implementations§

Source§

impl<T> Clone for LocalBoxFlow<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Flow for LocalBoxFlow<T>

Source§

type Item = T

The type of the values this flow emits.
Source§

type Run = Pin<Box<dyn Stream<Item = T>>>

One run of this flow.
Source§

fn open(&self) -> Self::Run

Starts a new, independent run.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for LocalBoxFlow<T>

§

impl<T> !Send for LocalBoxFlow<T>

§

impl<T> !Sync for LocalBoxFlow<T>

§

impl<T> !UnwindSafe for LocalBoxFlow<T>

§

impl<T> Forget for LocalBoxFlow<T>

§

impl<T> Freeze for LocalBoxFlow<T>
where Rc<dyn LocalErasedFlow<T>>: Freeze,

§

impl<T> Move for LocalBoxFlow<T>

§

impl<T> Unpin for LocalBoxFlow<T>
where Rc<dyn LocalErasedFlow<T>>: Unpin,

§

impl<T> UnsafeUnpin for LocalBoxFlow<T>
where Rc<dyn LocalErasedFlow<T>>: UnsafeUnpin,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> FlowExt for T
where T: Flow,

Source§

fn map<U, F>(self, transform: F) -> Map<Self, F>
where F: Fn(Self::Item) -> U + Clone,

Transforms each value.
Source§

fn filter<F>(self, predicate: F) -> Filter<Self, F>
where F: Fn(&Self::Item) -> bool + Clone,

Keeps only the values predicate accepts.
Source§

fn on_each<F>(self, action: F) -> OnEach<Self, F>
where F: Fn(&Self::Item) + Clone,

Runs action for each value before passing it on.
Source§

fn on_start<F>(self, action: F) -> OnStart<Self, F>
where F: Fn(),

Runs action each time a collection starts — Kotlin’s onStart.
Source§

fn on_completion<F>(self, action: F) -> OnCompletion<Self, F>
where F: Fn() + Clone,

Runs action when a collection ends, whether the upstream completed or the collector was cancelled — Kotlin’s onCompletion.
Source§

fn start_with(self, first: Self::Item) -> StartWith<Self>
where Self::Item: Clone,

Emits first before the upstream’s values — Kotlin’s onStart { emit(first) }.
Source§

fn scan<A, F>(self, initial: A, step: F) -> Scan<Self, A, F>
where A: Clone, F: Fn(&A, Self::Item) -> A + Clone,

Accumulates values, emitting initial and then every intermediate result — Kotlin’s scan / runningFold.
Source§

fn skip(self, count: usize) -> Skip<Self>

Ignores the first count values — Kotlin’s drop.
Source§

fn filter_map<U, F>(self, transform: F) -> FilterMap<Self, F>
where F: Fn(Self::Item) -> Option<U> + Clone,

Transforms each value and drops the Nones — Kotlin’s mapNotNull.
Source§

fn take(self, count: usize) -> Take<Self>

Emits the first count values, then stops and cancels the upstream.
Source§

fn take_while<P>(self, predicate: P) -> While<Self, P, Taking>
where P: Fn(&Self::Item) -> bool + Clone,

Emits values while predicate holds, then completes and cancels the upstream — Kotlin’s takeWhile.
Source§

fn skip_while<P>(self, predicate: P) -> While<Self, P, Skipping>
where P: Fn(&Self::Item) -> bool + Clone,

Ignores values while predicate holds, then emits every value — Kotlin’s dropWhile.
Source§

fn transform<U, F, Fut>( self, action: F, ) -> Suspending<Self, F, Transforming<U>, InOrder>
where F: FnOnce(Self::Item, Emitter<U>) -> Fut + Clone, Fut: Future<Output = ()>,

Emits whatever the suspending action emits for each value — Kotlin’s transform. Read more
Source§

fn transform_while<U, F, Fut>( self, action: F, ) -> Suspending<Self, F, TransformingWhile<U>, InOrder>
where F: FnOnce(Self::Item, Emitter<U>) -> Fut + Clone, Fut: Future<Output = bool>,

Like transform, but completes and cancels the upstream as soon as action returns false — Kotlin’s transformWhile.
Source§

fn transform_latest<U, F, Fut>( self, action: F, ) -> Suspending<Self, F, Transforming<U>, LatestOnly>
where F: FnOnce(Self::Item, Emitter<U>) -> Fut + Clone, Fut: Future<Output = ()>,

Like transform, but a newer value cancels the action still running for the previous one — Kotlin’s transformLatest.
Source§

fn map_async<F, Fut>( self, transform: F, ) -> Suspending<Self, F, Mapping, InOrder>
where F: FnOnce(Self::Item) -> Fut + Clone, Fut: Future,

Transforms each value with a suspending transform, one value at a time — Kotlin’s map with a suspend lambda. Read more
Source§

fn map_latest<F, Fut>( self, transform: F, ) -> Suspending<Self, F, Mapping, LatestOnly>
where F: FnOnce(Self::Item) -> Fut + Clone, Fut: Future,

Like map_async, but a newer value cancels the transformation still running for the previous one — Kotlin’s mapLatest.
Source§

fn filter_async<F, Fut>( self, predicate: F, ) -> Suspending<Self, F, Filtering, InOrder>
where Self::Item: Clone, F: FnOnce(Self::Item) -> Fut + Clone, Fut: Future<Output = bool>,

Keeps the values a suspending predicate accepts — Kotlin’s filter with a suspend lambda. The predicate gets a clone of each value.
Source§

fn filter_map_async<U, F, Fut>( self, transform: F, ) -> Suspending<Self, F, FilterMapping, InOrder>
where F: FnOnce(Self::Item) -> Fut + Clone, Fut: Future<Output = Option<U>>,

Transforms each value with a suspending transform and drops the Nones — Kotlin’s mapNotNull with a suspend lambda.
Source§

fn on_each_async<F, Fut>( self, action: F, ) -> Suspending<Self, F, Inspecting, InOrder>
where Self::Item: Clone, F: FnOnce(Self::Item) -> Fut + Clone, Fut: Future<Output = ()>,

Runs a suspending action on a clone of each value before emitting it — Kotlin’s onEach with a suspend lambda.
Source§

fn distinct_until_changed(self) -> DistinctUntilChanged<Self, WholeValue>
where Self::Item: PartialEq + Clone,

Drops values equal to the one emitted just before.
Source§

fn distinct_until_changed_by<K, F>( self, key: F, ) -> DistinctUntilChanged<Self, F>
where K: PartialEq, F: Fn(&Self::Item) -> K + Clone,

Drops values whose key equals the key of the value emitted just before — Kotlin’s distinctUntilChangedBy.
Source§

fn with_index(self) -> WithIndex<Self>

Pairs every value with its position, counting from zero — Kotlin’s withIndex.
Source§

fn running_reduce<R>(self, reducer: R) -> RunningReduce<Self, R>
where Self::Item: Clone, R: Fn(&Self::Item, Self::Item) -> Self::Item + Clone,

Emits the first value, then each value folded into the one emitted before — Kotlin’s runningReduce.
Source§

fn chunked(self, size: usize) -> Chunked<Self>

Groups values into vectors of size; the last one may be shorter — Kotlin’s chunked. A size of zero counts as one.
Source§

fn sample(self, period: Duration) -> Sample<Self>

Emits the latest value once per period, skipping periods without a new value — Kotlin’s sample. A value still waiting when the upstream completes is dropped.
Source§

fn timeout(self, limit: Duration) -> Timeout<Self>

Wraps values in Ok, and emits Err(TimedOut) and completes if the upstream goes limit without emitting — Kotlin’s timeout.
Source§

fn on_empty<F, Fut>(self, action: F) -> OnEmpty<Self, F>
where F: FnOnce(Emitter<Self::Item>) -> Fut + Clone, Fut: Future<Output = ()>,

Runs the suspending action if the flow completes without emitting, so it can emit a fallback — Kotlin’s onEmpty.
Source§

fn debounce(self, timeout: Duration) -> Debounce<Self>

Emits a value only after timeout passes without a newer one.
Source§

fn flat_map_latest<G, F>(self, transform: F) -> FlatMap<Self, F>
where G: Flow, F: Fn(Self::Item) -> G + Clone,

Maps each value to a flow and emits from the newest one, cancelling the run of the previous flow — Kotlin’s flatMapLatest.
Source§

fn flat_map_concat<G, F>(self, transform: F) -> FlatMap<Self, F>
where G: Flow, F: Fn(Self::Item) -> G + Clone,

Maps each value to a flow and emits all of it before taking the next value — Kotlin’s flatMapConcat.
Source§

fn flatten_concat(self) -> Flatten<Self>
where Self::Item: Flow,

Collects each inner flow in turn — Kotlin’s flattenConcat.
Source§

fn flatten_merge(self, concurrency: usize) -> Flatten<Self>
where Self::Item: Flow,

Collects up to concurrency inner flows at once, emitting their values as they arrive — Kotlin’s flattenMerge; Kotlin’s default concurrency is DEFAULT_CONCURRENCY.
Source§

fn flat_map_merge<G, F>( self, concurrency: usize, transform: F, ) -> FlatMap<Self, F>
where G: Flow, F: Fn(Self::Item) -> G + Clone,

Maps each value to a flow and runs up to concurrency of them at once, emitting values as they arrive — Kotlin’s flatMapMerge.
Source§

fn zip<O, U, F>(self, other: O, combiner: F) -> Zip<Self, O, F>
where O: Flow, F: Fn(Self::Item, O::Item) -> U + Clone,

Pairs the n-th value of this flow with the n-th value of other, completing when either completes — Kotlin’s zip.
Source§

fn combine<O, U, F>(self, other: O, combiner: F) -> Combine<Self, O, F>
where O: Flow, F: Fn(&Self::Item, &O::Item) -> U + Clone,

Combines the latest values of both flows once each has emitted.
Source§

fn catch<T, E, G, H>(self, handler: H) -> Catch<Self, H>
where Self: Flow<Item = Result<T, E>>, G: Flow<Item = T>, H: Fn(E) -> G + Clone,

On the first Err, stops the upstream and continues with the flow handler returns for the error — Kotlin’s catch.
Source§

fn retry<T, E>( self, attempts: u32, ) -> RetryWhen<Self, impl Fn(&E, u32) -> Option<Duration> + Clone>
where Self: Flow<Item = Result<T, E>> + Clone,

Runs the upstream again after an Err, up to attempts more times, and passes the last error on — Kotlin’s retry.
Source§

fn retry_when<T, E, P>(self, policy: P) -> RetryWhen<Self, P>
where Self: Flow<Item = Result<T, E>> + Clone, P: Fn(&E, u32) -> Option<Duration> + Clone,

Runs the upstream again after an Err when policy returns a back-off delay for that error and attempt, and passes the error on when it returns None — Kotlin’s retryWhen.
Source§

fn flow_on(self, dispatcher: Dispatcher) -> Buffered<Self>

Runs this flow’s upstream on dispatcher — Kotlin’s flowOn. Read more
Source§

fn buffer(self, capacity: usize) -> Buffered<Self>

Runs the upstream in its own coroutine on the collector’s dispatcher, letting it get up to capacity values ahead of a slow collector — Kotlin’s buffer.
Source§

fn conflate(self) -> Buffered<Self>

Runs the upstream in its own coroutine and hands a slow collector only the newest value — Kotlin’s conflate.
Source§

fn state_in<S>( self, scope: &S, started: SharingStarted, initial: Self::Item, ) -> StateFlow<Self::Item>
where S: Spawn<SharingTask<Self, StateFlow<Self::Item>>>, Self::Item: Clone + PartialEq,

Shares this flow as a hot StateFlow that runs in scope — Kotlin’s stateIn. Read more
Source§

fn state_in_first<S>(self, scope: &S) -> StateInFirst<Self::Item> ⓘ
where S: Spawn<FirstState<Self::Run>>, Self::Item: Clone + PartialEq,

Starts this flow in scope at once and waits for its first value, then returns a StateFlow that starts from it — Kotlin’s suspending stateIn(scope). None if the flow completes without emitting.
Source§

fn share_in<S>( self, scope: &S, started: SharingStarted, replay: usize, ) -> SharedFlow<Self::Item>
where S: Spawn<SharingTask<Self, MutableSharedFlow<Self::Item>>>, Self::Item: Clone,

Shares this flow as a hot SharedFlow that runs in scope and replays the last replay values to new collectors — Kotlin’s shareIn. Collectors may fall up to SHARE_IN_BUFFER values or replay, whichever is larger, behind; beyond that the upstream waits for them.
Source§

fn boxed(self) -> BoxFlow<Self::Item>
where Self: Send + Sync + 'static, Self::Run: Send + 'static,

Erases the type so the flow can sit behind a trait or be stored.
Source§

fn boxed_local(self) -> LocalBoxFlow<Self::Item>
where Self: 'static, Self::Run: 'static,

Erases the type of a flow that stays on one thread.
Source§

fn collect_async<F, Fut>(&self, action: F) -> CollectAsync<Self::Run, F>
where F: FnOnce(Self::Item) -> Fut + Clone, Fut: Future<Output = ()>,

Runs the flow, awaiting a suspending action for every value in turn, until it completes — Kotlin’s collect with a suspend lambda.
Source§

fn collect_latest<F, Fut>(&self, action: F) -> CollectLatest<Self::Run, F>
where F: FnOnce(Self::Item) -> Fut + Clone, Fut: Future<Output = ()>,

Runs the flow, cancelling the action still running for a value as soon as a newer value arrives — Kotlin’s collectLatest.
Source§

fn launch_in<S>(&self, scope: &S) -> Job
where S: Spawn<Collect<Self::Run, fn(Self::Item)>>,

Collects the flow in scope, ignoring its values — Kotlin’s launchIn, usually after on_each.
Source§

fn produce_in<S>(&self, scope: &S) -> Receiver<Self::Item>
where S: Spawn<ProduceIn<Self::Run>>,

Collects the flow in scope into a buffered channel and returns its receiving end — Kotlin’s produceIn. Dropping every receiver cancels the collection.
Source§

fn fold<A, F>(&self, initial: A, step: F) -> Fold<Self::Run, A, F> ⓘ
where F: FnMut(A, Self::Item) -> A,

Runs the flow, folding every value into an accumulator that starts at initial — Kotlin’s fold.
Source§

fn reduce<F>(&self, reducer: F) -> Reduce<Self::Run, F> ⓘ
where F: FnMut(Self::Item, Self::Item) -> Self::Item,

Runs the flow, folding every value into the first one; None for an empty flow — Kotlin’s reduceOrNull.
Source§

fn count(&self) -> Count<Self::Run, Self::Item>

Runs the flow and counts its values — Kotlin’s count.
Source§

fn last(&self) -> Last<Self::Run, Self::Item>

Runs the flow and returns its last value — Kotlin’s lastOrNull.
Source§

fn single(&self) -> Single<Self::Run> ⓘ

Returns the flow’s only value, or None once it turns out to have none or more than one — Kotlin’s singleOrNull.
Source§

fn collect<F>(&self, action: F) -> Collect<Self::Run, F> ⓘ
where F: FnMut(Self::Item),

Runs the flow, calling action for every value, until it completes.
Source§

fn first(&self) -> First<Self::Run> ⓘ

Runs the flow until its first value and returns it.
Source§

fn to_vec(&self) -> ToVec<Self::Run> ⓘ

Runs the flow to completion and gathers every value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.