pub struct Photon<T: Copy + Send + 'static> { /* private fields */ }Expand description
Named-topic pub/sub bus.
Wraps channel with string-keyed topic routing.
Each topic is an independent SPMC ring.
let bus = photon_ring::Photon::<u64>::new(64);
let mut pub_ = bus.publisher("prices");
let mut sub = bus.subscribe("prices");
pub_.publish(100);
assert_eq!(sub.try_recv(), Ok(100));Implementations§
Source§impl<T: Copy + Send + 'static> Photon<T>
impl<T: Copy + Send + 'static> Photon<T>
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(&self, topic: &str) -> Publisher<T>
pub fn publisher(&self, topic: &str) -> Publisher<T>
Take the publisher for a topic. Creates the topic if it doesn’t exist.
§Panics
Panics if the publisher for this topic was already taken.
Sourcepub fn subscribe(&self, topic: &str) -> Subscriber<T>
pub fn subscribe(&self, topic: &str) -> Subscriber<T>
Subscribe to a topic (future messages only). Creates the topic if needed.
Sourcepub fn subscribable(&self, topic: &str) -> Subscribable<T>
pub fn subscribable(&self, topic: &str) -> Subscribable<T>
Get the clone-able subscriber factory for a topic.
Auto Trait Implementations§
impl<T> !Freeze for Photon<T>
impl<T> !RefUnwindSafe for Photon<T>
impl<T> Send for Photon<T>
impl<T> Sync for Photon<T>
impl<T> Unpin for Photon<T>
impl<T> UnsafeUnpin for Photon<T>
impl<T> !UnwindSafe for Photon<T>
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