Topic

Struct Topic 

Source
pub struct Topic {
    pub address: Address,
    pub channel: Channel<Command>,
    pub subscribers: SubscriberBucket,
    pub cache: Vec<Transaction>,
    /* private fields */
}
Expand description

The main structure for representing Topics in the system. It will be the main interaction point for the user. Each Topic the user has will also require a copy of the same Topic in the Handler Thread. The only difference between the two is the opposing Channel, with which the two can communicate. TODO: The thread might require a dedicated struct. TODO: Add methods for fetching fields.

Fields§

§address: Address

Throughout the entire system all components have the same Address type. Each Topic also has a uniqe Address, which can be generated through any number of ways.

§channel: Channel<Command>

Since each Topic can receive messages individually a dedicated Channel (mpsc connection) is required.

§subscribers: SubscriberBucket

List of subscribers

§cache: Vec<Transaction>

The socket can get overread so a cache is required.

Implementations§

Source§

impl Topic

Source

pub fn new( address: Address, channel: Channel<Command>, subscribers: Vec<Address>, public: Address, ) -> Self

Creates a new Topic with a given Channel. This Topic is meant to be used both by the User and the Handler Thread. This function is not meant to be called by the user, since it requires the linked Channel to be stored on the Handler therad. Instead new Topics have to be created through the interface.

Source

pub fn recv(&mut self) -> Option<Transaction>

Blocking call to receive a Message from a Topic. It will only return once a Message from the system (usually from another user) is available or the Channel is unavailable. Since commands are sent over the same Channel the recv method takes a mutable reference to the Topic and can add / remove subscribers.

(Should it receive a Send message it will simply report an error.)

Source

pub fn try_recv(&mut self) -> Option<Transaction>

Behaves the same as “recv” but is non-blocking. Internally it still uses a loop to filter out non-user messages and will return on a User message or no message at all.

Source

pub fn broadcast(&mut self, body: Vec<u8>) -> Result<(), Error>

The main function for sending Messages to all subscribed users. It takes in a Vec, which represents the Body. In the future this has to be replaced by a Body trait object. There should also be an option to enable / disable encryption (but that would require integration with the Transaction & Wire objects for a dedicated field (or to make encryption mandatory (will require more tests))).

Source

pub fn unsubscribe(&mut self)

In the future this should be replaced by an automatic Drop implementation, currently a manual “unsubscribe” function is required to inform other users about the change. It simply sends an Unsubscribe action to each subscriber.

Source

pub fn address(&self) -> Address

Shorthand function to get the Address of a Topic.

Trait Implementations§

Source§

impl Drop for Topic

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Topic

§

impl RefUnwindSafe for Topic

§

impl Send for Topic

§

impl !Sync for Topic

§

impl Unpin for Topic

§

impl UnwindSafe for Topic

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V