pub struct KeyStream<K: Key, V: Value> { /* private fields */ }Expand description
The main entry point for key-based async message streaming.
Use KeyStream::new to create, then call KeyStream::sender to get a sender handle.
§Example
use key_stream::KeyStream;
use tokio;
let key_stream = KeyStream::<i32, String>::new(10);
let sender = key_stream.sender();
let mut receiver = sender.subscribe(1).await;
sender.send(&1, "value".to_string()).await.unwrap();
assert_eq!(receiver.recv().await.unwrap(), "value".to_string());Implementations§
Source§impl<K: Key, V: Value> KeyStream<K, V>
impl<K: Key, V: Value> KeyStream<K, V>
Sourcepub fn new(broadcast_capacity: usize) -> Self
pub fn new(broadcast_capacity: usize) -> Self
Create a new KeyStream with the given broadcast channel capacity per key.
Sourcepub fn sender(&self) -> KeySender<K, V>
pub fn sender(&self) -> KeySender<K, V>
Get a sender handle for publishing and subscribing to keys.
Sourcepub async fn keys_capacity(&self) -> usize
pub async fn keys_capacity(&self) -> usize
Get the current capacity of the keys map.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> !RefUnwindSafe for KeyStream<K, V>
impl<K, V> !UnwindSafe for KeyStream<K, V>
impl<K, V> Freeze for KeyStream<K, V>
impl<K, V> Send for KeyStream<K, V>
impl<K, V> Sync for KeyStream<K, V>
impl<K, V> Unpin for KeyStream<K, V>
impl<K, V> UnsafeUnpin for KeyStream<K, V>
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