Skip to main content

Scope

Struct Scope 

Source
pub struct Scope<'scope, 'env: 'scope> { /* private fields */ }
Expand description

A scope within which tasks can be spawned that borrow from the enclosing stack frame.

Implementations§

Source§

impl<'scope, 'env> Scope<'scope, 'env>

Source

pub fn spawn<Fut>(&'scope self, fut: Fut) -> ScopedJoinHandle<Fut::Output>
where Fut: Future + Send + 'scope, Fut::Output: Send + 'scope,

Spawn a task into this scope.

The future may borrow any data that outlives its lifetime 'env. The task will be polled cooperatively alongside the scope’s user closure and any other spawned tasks.

Source

pub fn spawn_abortable<Fut>( &'scope self, fut: Fut, ) -> AbortableJoinHandle<Fut::Output>
where Fut: Future + Send + 'scope, Fut::Output: Send + 'scope,

Spawn a task into this scope and return an AbortableJoinHandle.

This mirrors Executor::spawn_abortable for cooperatively scheduled tasks. The returned handle aborts the task when all references to it have been dropped.

Source

pub fn dispatch<Fut>(&'scope self, fut: Fut)
where Fut: Future + Send + 'scope, Fut::Output: Send + 'scope,

Spawn a task into this scope without keeping a handle to it.

Equivalent to Executor::dispatch for scoped tasks.

Source

pub fn spawn_coroutine<T, F, Fut>(&'scope self, f: F) -> CommunicationTask<T>
where F: FnMut(T) -> Fut + Send + 'scope, Fut: Future<Output = ()> + Send + 'scope, T: Send + 'scope,

Spawn a message-driven coroutine into this scope.

Equivalent to Executor::spawn_coroutine for scoped tasks.

Source

pub fn spawn_coroutine_with_buffer<T, F, Fut>( &'scope self, buffer: usize, f: F, ) -> CommunicationTask<T>
where F: FnMut(T) -> Fut + Send + 'scope, Fut: Future<Output = ()> + Send + 'scope, T: Send + 'scope,

Like Scope::spawn_coroutine but with a configurable channel buffer.

Source

pub fn spawn_unbounded_coroutine<T, F, Fut>( &'scope self, f: F, ) -> UnboundedCommunicationTask<T>
where F: FnMut(T) -> Fut + Send + 'scope, Fut: Future<Output = ()> + Send + 'scope, T: Send + 'scope,

Spawn an unbounded message-driven coroutine into this scope.

Equivalent to Executor::spawn_unbounded_coroutine for scoped tasks.

Source

pub fn spawn_coroutine_with_context<T, C, F, Fut>( &'scope self, context: C, f: F, ) -> CommunicationTask<T>
where F: FnMut(&mut C, T) -> Fut + Send + 'scope, Fut: Future<Output = ()> + Send + 'scope, C: Send + 'scope, T: Send + 'scope,

Spawn a message-driven coroutine with caller-provided context.

If the context must be borrowed across awaits, use Scope::spawn_coroutine_with_receiver_and_context.

Source

pub fn spawn_coroutine_with_buffer_and_context<T, C, F, Fut>( &'scope self, context: C, buffer: usize, f: F, ) -> CommunicationTask<T>
where F: FnMut(&mut C, T) -> Fut + Send + 'scope, Fut: Future<Output = ()> + Send + 'scope, C: Send + 'scope, T: Send + 'scope,

Like Scope::spawn_coroutine_with_context but with a configurable channel buffer.

Source

pub fn spawn_unbounded_coroutine_with_context<T, C, F, Fut>( &'scope self, context: C, f: F, ) -> UnboundedCommunicationTask<T>
where F: FnMut(&mut C, T) -> Fut + Send + 'scope, Fut: Future<Output = ()> + Send + 'scope, C: Send + 'scope, T: Send + 'scope,

Spawn an unbounded message-driven coroutine with caller-provided context.

Source

pub fn spawn_coroutine_with_receiver<T, F, Fut>( &'scope self, f: F, ) -> CommunicationTask<T>
where F: FnMut(Receiver<T>) -> Fut, Fut: Future<Output = ()> + Send + 'scope,

Spawn a coroutine that receives the bounded channel directly.

Source

pub fn spawn_coroutine_with_receiver_and_buffer<T, F, Fut>( &'scope self, buffer: usize, f: F, ) -> CommunicationTask<T>
where F: FnMut(Receiver<T>) -> Fut, Fut: Future<Output = ()> + Send + 'scope,

Like Scope::spawn_coroutine_with_receiver but with a configurable channel buffer.

Source

pub fn spawn_coroutine_with_receiver_and_context<T, F, C, Fut>( &'scope self, context: C, f: F, ) -> CommunicationTask<T>
where F: FnMut(C, Receiver<T>) -> Fut, Fut: Future<Output = ()> + Send + 'scope,

Spawn a coroutine that receives caller-provided context and the bounded channel directly.

Source

pub fn spawn_coroutine_with_receiver_buffer_and_context<T, F, C, Fut>( &'scope self, context: C, buffer: usize, f: F, ) -> CommunicationTask<T>
where F: FnMut(C, Receiver<T>) -> Fut, Fut: Future<Output = ()> + Send + 'scope,

Like Scope::spawn_coroutine_with_receiver_and_context but with a configurable channel buffer.

Source

pub fn spawn_unbounded_coroutine_with_receiver<T, F, Fut>( &'scope self, f: F, ) -> UnboundedCommunicationTask<T>
where F: FnMut(UnboundedReceiver<T>) -> Fut, Fut: Future<Output = ()> + Send + 'scope,

Spawn a coroutine that receives the unbounded channel directly.

Source

pub fn spawn_unbounded_coroutine_with_receiver_and_context<T, F, C, Fut>( &'scope self, context: C, f: F, ) -> UnboundedCommunicationTask<T>
where F: FnMut(C, UnboundedReceiver<T>) -> Fut, Fut: Future<Output = ()> + Send + 'scope,

Spawn a coroutine that receives caller-provided context and the unbounded channel directly.

Source

pub fn spawn_timeout<F>( &'scope self, duration: Duration, f: F, ) -> ScopedJoinHandle<Result<F::Output, TimeoutError>>
where F: Future + Send + 'scope, F::Output: Send + 'scope,

Spawn a scoped task that must complete within duration.

If the future does not finish before duration elapses, it is dropped and the task completes with TimeoutError. This is the scoped analogue of ExecutorTimeout::spawn_timeout.

Source

pub fn spawn_delay<F>( &'scope self, duration: Duration, f: F, ) -> ScopedJoinHandle<F::Output>
where F: Future + Send + 'scope, F::Output: Send + 'scope,

Spawns a task after waiting for a duration before the task is polled.

Source

pub fn spawn_abortable_timeout<F>( &'scope self, duration: Duration, f: F, ) -> AbortableJoinHandle<Result<F::Output, TimeoutError>>
where F: Future + Send + 'scope, F::Output: Send + 'scope,

Spawn a scoped task that must complete within duration, returning an AbortableJoinHandle that cancels the task once all references to it are dropped.

If the future does not finish before duration elapses, it is dropped and the task completes with TimeoutError.

Source

pub fn spawn_abortable_delay<F>( &'scope self, duration: Duration, f: F, ) -> AbortableJoinHandle<F::Output>
where F: Future + Send + 'scope, F::Output: Send + 'scope,

Spawns a task after waiting for a duration before the task is polled.

Auto Trait Implementations§

§

impl<'scope, 'env> !RefUnwindSafe for Scope<'scope, 'env>

§

impl<'scope, 'env> !UnwindSafe for Scope<'scope, 'env>

§

impl<'scope, 'env> Freeze for Scope<'scope, 'env>

§

impl<'scope, 'env> Send for Scope<'scope, 'env>

§

impl<'scope, 'env> Sync for Scope<'scope, 'env>

§

impl<'scope, 'env> Unpin for Scope<'scope, 'env>

§

impl<'scope, 'env> UnsafeUnpin for Scope<'scope, 'env>

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, 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 = !

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.