Struct Peer

Source
pub struct Peer<const CONFIG: u64, LocalMessages: ReactiveMessagingSerializer<LocalMessages> + Send + Sync + PartialEq + Debug + 'static, SenderChannel: FullDuplexUniChannel<ItemType = LocalMessages, DerivedItemType = LocalMessages> + Send + Sync, StateType: Send + Sync + Clone + Debug + 'static = ()> {
    pub peer_id: ConnectionId,
    pub peer_address: SocketAddr,
    pub state: Mutex<Option<StateType>>,
    /* private fields */
}
Expand description

Represents a reactive channel connected to a remote peer, through which we’re able to send out “local messages” of type RetryableSenderImpl::LocalMessages.
the Self::send() method honors whatever retrying config is specified in [RetryableSenderImpl::CONST_CONFIG]. IMPLEMENTATION NOTE: GAT traits (to reduce the number of generic parameters) couldn’t be used here – even after applying this compiler bug workaround https://github.com/rust-lang/rust/issues/102211#issuecomment-1513931928 – the “error: implementation of std::marker::Send is not general enough” bug kept on popping up in user provided closures that called other async functions.

Fields§

§peer_id: ConnectionId§peer_address: SocketAddr§state: Mutex<Option<StateType>>

Implementations§

Source§

impl<const CONFIG: u64, LocalMessages: ReactiveMessagingSerializer<LocalMessages> + Send + Sync + PartialEq + Debug, SenderChannel: FullDuplexUniChannel<ItemType = LocalMessages, DerivedItemType = LocalMessages> + Send + Sync, StateType: Send + Sync + Clone + Debug> Peer<CONFIG, LocalMessages, SenderChannel, StateType>

Source

pub fn new( retryable_sender: ReactiveMessagingSender<CONFIG, LocalMessages, SenderChannel>, peer_address: SocketAddr, connection: &SocketConnection<StateType>, ) -> Self

Source

pub fn config(&self) -> ConstConfig

Source

pub fn create_stream( &self, ) -> (MutinyStream<'static, LocalMessages, SenderChannel, LocalMessages>, u32)

Asks the underlying channel to revert to Stream-mode (rather than Execution-mode), returning the Stream

Source

pub fn send(&self, message: LocalMessages) -> Result<(), (bool, String)>

Source

pub async fn send_async( &self, message: LocalMessages, ) -> Result<(), (bool, String)>

Source

pub async fn set_state(&self, state: StateType)

Sets this object to a user-provided state, to facilitate communications between protocol processors (a requirement to allow the “Composite Protocol Stacking” pattern).
See also Self::take_state()

Source

pub fn try_set_state(&self, state: StateType) -> bool

Use [set_state()] (async) if possible

Source

pub async fn take_state(&self) -> Option<StateType>

“Takes” this object’s user-provided state, previously set by Self::set_state() – used to facilitate communications between protocol processors (a requirement to allow the “Composite Protocol Stacking” pattern)

Source

pub fn try_take_state(&self) -> Option<Option<StateType>>

Use Self::take_state() (async) if possible

Source

pub fn pending_items_count(&self) -> u32

Source

pub fn buffer_size(&self) -> u32

Source

pub async fn flush_and_close(&self, timeout: Duration) -> u32

Source

pub fn cancel_and_close(&self)

Trait Implementations§

Source§

impl<const CONFIG: u64, LocalMessages: ReactiveMessagingSerializer<LocalMessages> + Send + Sync + PartialEq + Debug, SenderChannel: FullDuplexUniChannel<ItemType = LocalMessages, DerivedItemType = LocalMessages> + Send + Sync, StateType: Send + Sync + Clone + Debug> Debug for Peer<CONFIG, LocalMessages, SenderChannel, StateType>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const CONFIG: u64, LocalMessages, SenderChannel, StateType = ()> !Freeze for Peer<CONFIG, LocalMessages, SenderChannel, StateType>

§

impl<const CONFIG: u64, LocalMessages, SenderChannel, StateType = ()> !RefUnwindSafe for Peer<CONFIG, LocalMessages, SenderChannel, StateType>

§

impl<const CONFIG: u64, LocalMessages, SenderChannel, StateType> Send for Peer<CONFIG, LocalMessages, SenderChannel, StateType>

§

impl<const CONFIG: u64, LocalMessages, SenderChannel, StateType> Sync for Peer<CONFIG, LocalMessages, SenderChannel, StateType>

§

impl<const CONFIG: u64, LocalMessages, SenderChannel, StateType> Unpin for Peer<CONFIG, LocalMessages, SenderChannel, StateType>
where StateType: Unpin,

§

impl<const CONFIG: u64, LocalMessages, SenderChannel, StateType = ()> !UnwindSafe for Peer<CONFIG, LocalMessages, SenderChannel, StateType>

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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