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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::{collections::BTreeMap, convert::Infallible, fmt::Display};
use serde::de::DeserializeOwned;
pub trait FromRaw: Sized {
type Raw: DeserializeOwned;
fn from_raw(_: Self::Raw) -> Self;
}
pub trait TryFromRaw: Sized {
type Raw: DeserializeOwned;
type Err: Display;
fn try_from_raw(_: Self::Raw) -> Result<Self, Self::Err>;
}
impl FromRaw for ruma_serde::empty::Empty {
type Raw = Self;
fn from_raw(raw: Self) -> Self {
raw
}
}
impl FromRaw for serde_json::Value {
type Raw = Self;
fn from_raw(raw: Self) -> Self {
raw
}
}
impl<K, V> FromRaw for BTreeMap<K, V>
where
Self: DeserializeOwned,
{
type Raw = Self;
fn from_raw(raw: Self) -> Self {
raw
}
}
impl<T: FromRaw> TryFromRaw for T {
type Raw = <T as FromRaw>::Raw;
type Err = Infallible;
fn try_from_raw(raw: Self::Raw) -> Result<Self, Self::Err> {
Ok(Self::from_raw(raw))
}
}