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

use crate::StdResult;

/// From message adapter trait
pub trait FromMessageAdapter<U, V> {
    /// Adapt entity to message
    fn adapt(from: U) -> V;
}

/// TryFrom message adapter trait
pub trait TryFromMessageAdapter<U, V> {
    /// Adapt entity to message
    fn try_adapt(from: U) -> StdResult<V>;
}

/// To message adapter trait
pub trait ToMessageAdapter<U, V>
where
    V: Serialize + for<'a> Deserialize<'a>,
{
    /// Adapt message to entity
    fn adapt(from: U) -> V;
}

/// TryTo message adapter trait
pub trait TryToMessageAdapter<U, V> {
    /// Adapt message to entity
    fn try_adapt(from: U) -> StdResult<V>;
}