ThreadSafeSenderAndReceiver

Trait ThreadSafeSenderAndReceiver 

Source
pub trait ThreadSafeSenderAndReceiver<P>:
    SenderAndReceiver<P>
    + Send
    + Sync
where P: PoolItem,
{ }
Expand description

A thread-safe version of SenderAndReceiver.

This trait is useful when building nested thread pools, where inner thread pools need to be Send + Sync to be shared across the outer pool’s threads.

§Example: Nested Thread Pools

use std::sync::Arc;
use messaging_thread_pool::{ThreadPool, ThreadSafeSenderAndReceiver};

struct OuterItem<T: ThreadSafeSenderAndReceiver<InnerItem>> {
    id: u64,
    inner_pool: Arc<T>,  // Shared across outer pool threads
}

See samples::RandomsBatch for a complete example of nested thread pools.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§