Skip to main content

SendPeer

Struct SendPeer 

pub struct SendPeer<P> { /* private fields */ }
Expand description

A StoreSyncPeer or RemoteSyncPeer of the SendSyncPeer flavour.

It answers exactly as the peer it wraps: each method delegates, and the Error and Resume are the wrapped peer’s. What it adds is the promise: its futures are Send, so a function generic over SendSyncPeer can hold them across a tokio::spawn. Through trait_variant’s blanket impl it is a bare SyncPeer too.

It implements the flavour for two peers and their Send halves:

Sync because a pull or a push holds &self across its awaits, and a borrow is Send only when what it borrows is Sync.

It is not a wrapper for any SyncPeer. A bare peer’s futures promise nothing about Send, and stable Rust has no way to ask “whose pull future is Send” of a generic P, so the impl is written per peer, where the halves’ own flavours supply the promise.

§Examples

use happenstance_sync::{SendPeer, SendSyncPeer, StoreSyncPeer};

// Generic code that may spawn knows the peer by the `Send` flavour only.
fn spawnable<P: SendSyncPeer + Sync>(_peer: &P) {}

let hub = Shared(std::sync::Arc::new(happenstance_sync::MemoryIngestStore::new()));
let peer = SendPeer::new(StoreSyncPeer::new(hub.clone(), hub));
spawnable(&peer);

Implementations§

§

impl<P> SendPeer<P>

pub const fn new(peer: P) -> Self

The Send flavour of peer.

pub const fn get_ref(&self) -> &P

The wrapped peer.

pub fn into_inner(self) -> P

The wrapped peer, handed back.

Trait Implementations§

§

impl<P: Clone> Clone for SendPeer<P>

§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<P: Debug> Debug for SendPeer<P>

§

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

Formats the value using the given formatter. Read more
§

impl<S, I, A> SendSyncPeer for SendPeer<StoreSyncPeer<S, I, A>>

§

async fn pull( &self, from: Option<&StoreResume>, ) -> Result<Pulled<StoreResume>, Self::Error>

StoreSyncPeer’s pull.

§Errors

As StoreSyncPeer’s pull.

§

async fn push(&self, batch: &PushBatch) -> Result<Ack, Self::Error>

StoreSyncPeer’s push.

§Errors

As StoreSyncPeer’s push.

§

type Error = <StoreSyncPeer<S, I, A> as SyncPeer>::Error

How this peer’s transport fails; each failure states its class. Read more
§

type Resume = StoreResume

Where to resume from: opaque to the caller, owned by the caller. Read more
§

fn limits(&self) -> PeerLimits

What this peer can accept, readable before a push rather than discovered as an error after one. Read more
§

impl<X> SendSyncPeer for SendPeer<RemoteSyncPeer<X>>
where X: SendExchange + Sync,

§

async fn pull( &self, from: Option<&ResumeToken>, ) -> Result<Pulled<ResumeToken>, Self::Error>

RemoteSyncPeer’s pull: one Route::Pull exchange.

§Errors

As RemoteSyncPeer’s pull.

§

async fn push(&self, batch: &PushBatch) -> Result<Ack, Self::Error>

RemoteSyncPeer’s push: one Route::Push exchange, or none when the declared limits refuse the batch.

§Errors

As RemoteSyncPeer’s push.

§

type Error = <RemoteSyncPeer<X> as SyncPeer>::Error

How this peer’s transport fails; each failure states its class. Read more
§

type Resume = ResumeToken

Where to resume from: opaque to the caller, owned by the caller. Read more
§

fn limits(&self) -> PeerLimits

What this peer can accept, readable before a push rather than discovered as an error after one. Read more

Auto Trait Implementations§

§

impl<P> Freeze for SendPeer<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for SendPeer<P>
where P: RefUnwindSafe,

§

impl<P> Send for SendPeer<P>
where P: Send,

§

impl<P> Sync for SendPeer<P>
where P: Sync,

§

impl<P> Unpin for SendPeer<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for SendPeer<P>
where P: UnsafeUnpin,

§

impl<P> UnwindSafe for SendPeer<P>
where P: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.

§

impl<TraitVariantBlanketType> SyncPeer for TraitVariantBlanketType
where TraitVariantBlanketType: SendSyncPeer,

§

type Error = <TraitVariantBlanketType as SendSyncPeer>::Error

How this peer’s transport fails; each failure states its class. Read more
§

type Resume = <TraitVariantBlanketType as SendSyncPeer>::Resume

Where to resume from: opaque to the caller, owned by the caller. Read more
§

async fn pull( &self, from: Option<&<TraitVariantBlanketType as SyncPeer>::Resume>, ) -> Result<Pulled<<TraitVariantBlanketType as SyncPeer>::Resume>, <TraitVariantBlanketType as SyncPeer>::Error>

Fetches the next batch of events the far side holds and this side does not, plus the token to resume after them. Read more
§

async fn push( &self, batch: &PushBatch, ) -> Result<Ack, <TraitVariantBlanketType as SyncPeer>::Error>

Offers a batch of events to the far side. Read more
§

fn limits(&self) -> PeerLimits

What this peer can accept, readable before a push rather than discovered as an error after one. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.