mm1_core/context/
tell.rs

1
2
3
4
5
6
7
8
9
10
11
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
37
use std::any::Any;
use std::future::Future;

use mm1_address::address::Address;
use mm1_common::errors::error_of::ErrorOf;
use mm1_common::impl_error_kind;

use crate::context::Call;
use crate::message::AnyMessage;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum TellErrorKind {
    InternalError,
    NotFound,
    Closed,
    Full,
}

pub trait Tell: Call<Address, AnyMessage, Outcome = Result<(), ErrorOf<TellErrorKind>>> {
    fn tell<M>(
        &mut self,
        to: Address,
        msg: M,
    ) -> impl Future<Output = Result<(), ErrorOf<TellErrorKind>>> + Send
    where
        M: Any + Send + 'static,
    {
        async move {
            let message = AnyMessage::new(msg);
            self.call(to, message).await
        }
    }
}

impl<T> Tell for T where T: Call<Address, AnyMessage, Outcome = Result<(), ErrorOf<TellErrorKind>>> {}

impl_error_kind!(TellErrorKind);