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
use {
std::convert::TryFrom,
async_proto_derive::impl_protocol_for,
crate::{
Protocol,
ReadError,
},
};
#[derive(Protocol)]
#[async_proto(internal)]
struct TzProxy {
name: String,
}
impl TryFrom<TzProxy> for chrono_tz::Tz {
type Error = ReadError;
fn try_from(TzProxy { name }: TzProxy) -> Result<Self, ReadError> {
name.parse().map_err(ReadError::Custom)
}
}
impl<'a> From<&'a chrono_tz::Tz> for TzProxy {
fn from(tz: &chrono_tz::Tz) -> Self {
Self { name: tz.name().to_owned() }
}
}
impl_protocol_for! {
#[cfg_attr(docsrs, doc(cfg(feature = "chrono-tz")))]
#[async_proto(via = TzProxy)]
type chrono_tz::Tz;
}