SideA

Struct SideA 

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

Side A endpoint (request sender, response receiver)

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. Wait for channel to be idle (if previous request is still being processed)
  2. Send request to side B
  3. Wait for side B’s response
  4. Return the response

发送请求并等待响应

这个方法会:

  1. 等待 channel 进入空闲状态(如果之前的请求还在处理中)
  2. 发送请求到 B 方
  3. 等待 B 方的响应
  4. 返回响应
§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 response = guard.request().len() as i32;
        guard.reply(response);
    }
});
 
let response = side_a.request("Hello".to_string()).await;
assert_eq!(response, Ok(5));

Trait Implementations§

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