Struct interlink::msg::Mr

source ·
pub struct Mr<M: Message>(pub M::Response);
Expand description

Message Response

Response type from a handler which directly sends a response for a specific message

use interlink::prelude::*;

#[derive(Service)]
struct Test { value: String };

#[derive(Message)]
#[msg(rtype="String")]
struct TestMessage {
    value: String,
}

impl Handler<TestMessage> for Test {
    type Response = Mr<TestMessage>;

    fn handle(&mut self, msg: TestMessage, ctx: &mut ServiceContext<Self>) -> Self::Response {
        self.value = msg.value;

        Mr("Response".to_string())
    }
}

#[tokio::test]
async fn test() {
    let service = Test { value: "Default".to_string() };
    let link = service.start();
     
    let res: String = link
        .send(TestMessage {
            value: "Example".to_string()
        })
        .await
        .unwrap();
     
    assert_eq!(&res, "Response")    

}

Tuple Fields§

§0: M::Response

Trait Implementations§

source§

impl<S, M> ResponseHandler<S, M> for Mr<M>where S: Service, M: Message,

source§

fn respond( self, _service: &mut S, _ctx: &mut ServiceContext<S>, tx: Option<Sender<M::Response>> )

Auto Trait Implementations§

§

impl<M> RefUnwindSafe for Mr<M>where <M as Message>::Response: RefUnwindSafe,

§

impl<M> Send for Mr<M>

§

impl<M> Sync for Mr<M>where <M as Message>::Response: Sync,

§

impl<M> Unpin for Mr<M>where <M as Message>::Response: Unpin,

§

impl<M> UnwindSafe for Mr<M>where <M as Message>::Response: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.