pub struct MessageRequest<Req, Res, S = Bincode>where
    S: Serializer<Res>,{ /* private fields */ }
Expand description

Message containing a request, allowing for a response to be sent back.

Message requests can be created using MessageRequest::new.

A message request should always have reply called, otherwise a process could be left waiting forever for a response (unless receive_timeout is used).

Implementations§

source§

impl<Req, Res, S> MessageRequest<Req, Res, S>where S: Serializer<Res>,

source

pub fn new(req: Req) -> (Self, TaggedMailbox<Res, S>)

Creates a new MessageRequest and TaggedMailbox.

The tagged mailbox can be used to wait for a response using TaggedMailbox::receive.

Internally, this method creates a tag which is shared between the message request and tagged mailbox.

source

pub fn into_parts(self) -> (PendingProcess<Res, S>, Req)

Splits the message request into a PendingProcess and the inner request.

This is useful if you need ownership of the inner request directly.

source

pub fn reply(self, res: Res)where Res: Serialize + DeserializeOwned,

Replies to the process with a response.

Examples found in repository?
examples/counter.rs (line 21)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
    let counter = spawn_link!(|mailbox: Mailbox<Message>| {
        let mut count = 0;

        loop {
            let msg = mailbox.receive();
            match msg {
                Message::Inc => count += 1,
                Message::Dec => count -= 1,
                Message::Count(req) => req.reply(count),
            }
        }
    });

    // Initial count should be 0
    let count = counter.request(Message::Count, ());
    assert_eq!(count, 0);

    // Increment count
    counter.send(Message::Inc);

    // Count should now be 1
    let count = counter.request(Message::Count, ());
    assert_eq!(count, 1);
}

Trait Implementations§

source§

impl<Req: Clone, Res: Clone, S> Clone for MessageRequest<Req, Res, S>where S: Serializer<Res> + Clone,

source§

fn clone(&self) -> MessageRequest<Req, Res, S>

Returns a copy 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: Debug, Res: Debug, S> Debug for MessageRequest<Req, Res, S>where S: Serializer<Res> + Debug,

source§

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

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

impl<Req, Res, S> Deref for MessageRequest<Req, Res, S>where S: Serializer<Res>,

§

type Target = Req

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<Req, Res, S> DerefMut for MessageRequest<Req, Res, S>where S: Serializer<Res>,

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'de, Req, Res, S> Deserialize<'de> for MessageRequest<Req, Res, S>where S: Serializer<Res>, Req: Serialize + for<'dee> Deserialize<'dee>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<Req: PartialEq, Res: PartialEq, S> PartialEq<MessageRequest<Req, Res, S>> for MessageRequest<Req, Res, S>where S: Serializer<Res> + PartialEq,

source§

fn eq(&self, other: &MessageRequest<Req, Res, S>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Req, Res, S> Serialize for MessageRequest<Req, Res, S>where S: Serializer<Res>, Req: Serialize + for<'dee> Deserialize<'dee>,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<Req: Copy, Res: Copy, S> Copy for MessageRequest<Req, Res, S>where S: Serializer<Res> + Copy,

source§

impl<Req: Eq, Res: Eq, S> Eq for MessageRequest<Req, Res, S>where S: Serializer<Res> + Eq,

source§

impl<Req, Res, S> StructuralEq for MessageRequest<Req, Res, S>where S: Serializer<Res>,

source§

impl<Req, Res, S> StructuralPartialEq for MessageRequest<Req, Res, S>where S: Serializer<Res>,

Auto Trait Implementations§

§

impl<Req, Res, S> RefUnwindSafe for MessageRequest<Req, Res, S>where Req: RefUnwindSafe, Res: RefUnwindSafe, S: RefUnwindSafe,

§

impl<Req, Res, S> Send for MessageRequest<Req, Res, S>where Req: Send, Res: Send, S: Send,

§

impl<Req, Res, S> Sync for MessageRequest<Req, Res, S>where Req: Sync, Res: Sync, S: Sync,

§

impl<Req, Res, S> Unpin for MessageRequest<Req, Res, S>where Req: Unpin, Res: Unpin, S: Unpin,

§

impl<Req, Res, S> UnwindSafe for MessageRequest<Req, Res, S>where Req: UnwindSafe, Res: UnwindSafe, S: 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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere T: Clone,

§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,