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
use crate::{Message, Result};
use serde::{Deserialize, Serialize};

/// Message that is meant to be sent between workers if Error-handling is needed.
#[derive(Serialize, Deserialize)]
pub struct ResultMessage<M: Message>(Result<M>);

impl<M> ResultMessage<M>
where
    M: Message,
{
    /// Constructor
    pub fn new(inner: Result<M>) -> Self {
        Self(inner)
    }
}

impl<M: Message> From<Result<M>> for ResultMessage<M> {
    fn from(other: Result<M>) -> Self {
        Self::new(other)
    }
}

#[allow(clippy::from_over_into)]
impl<M: Message> Into<Result<M>> for ResultMessage<M> {
    fn into(self) -> Result<M> {
        self.0
    }
}