pub struct TypedBus { /* private fields */ }Expand description
A topic bus that supports different message types per topic.
Unlike Photon<T> which requires a single message type
across all topics, TypedBus allows each topic to have its own
T: Copy + Send + 'static.
§Example
use photon_ring::TypedBus;
let bus = TypedBus::new(1024);
// Different types per topic
let mut price_pub = bus.publisher::<f64>("prices");
let mut vol_pub = bus.publisher::<u32>("volumes");
let mut price_sub = bus.subscribe::<f64>("prices");
let mut vol_sub = bus.subscribe::<u32>("volumes");
price_pub.publish(42.5);
vol_pub.publish(1000);
assert_eq!(price_sub.try_recv(), Ok(42.5));
assert_eq!(vol_sub.try_recv(), Ok(1000));Implementations§
Source§impl TypedBus
impl TypedBus
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a bus. capacity is the ring size for each topic (power of two).
Sourcepub fn publisher<T: Copy + Send + 'static>(&self, topic: &str) -> Publisher<T>
pub fn publisher<T: Copy + Send + 'static>(&self, topic: &str) -> Publisher<T>
Take the publisher for a topic. Creates the topic if it doesn’t exist.
§Panics
- Panics if the topic already exists with a different type
T. - Panics if the publisher for this topic was already taken.
Sourcepub fn subscribe<T: Copy + Send + 'static>(&self, topic: &str) -> Subscriber<T>
pub fn subscribe<T: Copy + Send + 'static>(&self, topic: &str) -> Subscriber<T>
Subscribe to a topic (future messages only). Creates the topic if needed.
§Panics
Panics if the topic already exists with a different type T.
Sourcepub fn subscribable<T: Copy + Send + 'static>(
&self,
topic: &str,
) -> Subscribable<T>
pub fn subscribable<T: Copy + Send + 'static>( &self, topic: &str, ) -> Subscribable<T>
Get the clone-able subscriber factory for a topic.
§Panics
Panics if the topic already exists with a different type T.
Auto Trait Implementations§
impl !Freeze for TypedBus
impl !RefUnwindSafe for TypedBus
impl Send for TypedBus
impl Sync for TypedBus
impl Unpin for TypedBus
impl UnsafeUnpin for TypedBus
impl !UnwindSafe for TypedBus
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