SideA

Struct SideA 

Source
pub struct SideA<Req, Resp> { /* private fields */ }
Expand description

Side A endpoint (request sender, response receiver) - can be cloned

A 方的 channel 端点(请求发送方,响应接收方)- 可以克隆

Implementations§

Source§

impl<Req, Resp> SideA<Req, Resp>

Source

pub async fn request(&self, req: Req) -> Result<Resp, ChannelError>

Send a request and wait for response

This method will:

  1. Push request to the queue
  2. Wait for side B to process and respond
  3. Return the response

发送请求并等待响应

这个方法会:

  1. 将请求推入队列
  2. 等待 B 方处理并响应
  3. 返回响应
§Returns
  • Ok(response): Received response from side B
  • Err(ChannelError::Closed): Side B has been closed
§Example
let (side_a, side_b) = channel::<String, i32>();
 
tokio::spawn(async move {
    while let Ok(guard) = side_b.recv_request().await {
        let len = guard.request().len() as i32;
        guard.reply(len);
    }
});
 
let response = side_a.request("Hello".to_string()).await;
assert_eq!(response, Ok(5));
Source

pub fn try_request( &self, req: Req, ) -> Result<impl Future<Output = Result<Resp, ChannelError>>, ChannelError>

Try to send a request without waiting for response

Returns a future that will resolve to the response.

尝试发送请求但不等待响应

返回一个 future,将解析为响应。

Trait Implementations§

Source§

impl<Req, Resp> Clone for SideA<Req, Resp>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Req, Resp> Debug for SideA<Req, Resp>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<Req, Resp> Drop for SideA<Req, Resp>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<Req, Resp> Freeze for SideA<Req, Resp>

§

impl<Req, Resp> !RefUnwindSafe for SideA<Req, Resp>

§

impl<Req, Resp> Send for SideA<Req, Resp>
where Req: Send, Resp: Send,

§

impl<Req, Resp> Sync for SideA<Req, Resp>
where Req: Send, Resp: Send,

§

impl<Req, Resp> Unpin for SideA<Req, Resp>

§

impl<Req, Resp> !UnwindSafe for SideA<Req, Resp>

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.

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