Skip to main content

Hub

Struct Hub 

Source
pub struct Hub { /* private fields */ }
Available on crate feature hub only.
Expand description

The shared frame bus. Create with Hub::new and attach ports.

Hub is always used behind an Arc so that listener and uplink tasks can share it. It holds no sockets itself: tasks such as serve_tcp attach a Port per connection and drop it when the connection ends.

Implementations§

Source§

impl Hub

Source

pub fn new() -> Arc<Hub> ⓘ

Create an empty hub with no ports.

Source

pub fn port(&self) -> Port

Attach a new port. Frames it sends go to every other port.

The port only receives frames sent after it was created. Dropping the port detaches it.

use rolcb::hub::Hub;

let hub = Hub::new();
let a = hub.port();
let mut b = hub.port();
let frame = rolcb::gridconnect::parse(":X10700285N;").unwrap();
a.send(frame);
assert_eq!(b.recv().await, Some(frame));
Source

pub fn port_count(&self) -> usize

Number of ports currently attached (including ones created with Hub::port by the application). Falls as ports are dropped.

Trait Implementations§

Source§

impl Debug for Hub

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Hub

§

impl RefUnwindSafe for Hub

§

impl Send for Hub

§

impl Sync for Hub

§

impl Unpin for Hub

§

impl UnsafeUnpin for Hub

§

impl UnwindSafe for Hub

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.