Trait conch_runtime::spawn::SpawnRef[][src]

pub trait SpawnRef<E: ?Sized> {
    type EnvFuture: EnvFuture<E, Item = Self::Future, Error = Self::Error>;
    type Future: Future<Item = ExitStatus, Error = Self::Error>;
    type Error;
    fn spawn_ref(&self, env: &E) -> Self::EnvFuture;
}

A marker trait for denoting that the receiver of a Spawn implementation can also be spawned by reference without moving. Automatically derived for any &'a T: Spawn.

Until Associated Type Constructors (ATCs) land, we cannot define a version of Spawn which takes the receiver by reference since there is no way we reference the receiver's lifetime within the associated futures.

We can, however, get around this by defining Spawn to move its receiver, and then implementing the trait directly on a reference (this moves the reference, but references are Copy which is effectively a no-op). That way we can tie the associated futures to the lifetime of the reference since neither can outlive the actual struct.

This effectively gives rise to two Spawn implementations we can add on each type: one that moves the caller and any inner types by value, and one that operates on the outer and inner types by reference only. As long as we don't mix the two kinds, we're golden!

Except there are situations where we may want to own a type directly, but want to spawn it by reference (imagine we're running a loop on an "owned" implementation chain and need to spawn something repeatedly, but we don't want to clone deeply nested types)... Unfortunately, doing so confuses the compiler which causes it to get stuck in a recursive loop when evaluating bounds (error is E0275 with a message like "required by the impl for &T<_> because of the requirements on the impl for &T<T<_>>, &T<T<T<_>>>, ...").

We can apparently point the compiler in the right direction by adding a marker trait only when Spawn is implemented directly on a reference, allowing it to avoid the first "owned" implementation on the same type.

Associated Types

The future that represents spawning the command.

It represents all computations that may need an environment to progress further.

The future that represents the exit status of a fully bootstrapped command, which no longer requires an environment to be driven to completion.

The type of error that a future will resolve with if it fails in a normal fashion.

Required Methods

Identical to Spawn::spawn but does not move self.

Implementations on Foreign Types

impl<T: ?Sized, E: ?Sized> SpawnRef<E> for Rc<T> where
    T: 'static + SpawnBoxed<E>,
    E: 'static, 
[src]

impl<T: ?Sized, E: ?Sized> SpawnRef<E> for Arc<T> where
    T: 'static + SpawnBoxed<E>,
    E: 'static, 
[src]

Implementors