Skip to main content

TypedBus

Struct TypedBus 

Source
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

Source

pub fn new(capacity: usize) -> Self

Create a bus. capacity is the ring size for each topic (power of two).

Source

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.
Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.