async_proto/impls/
chrono_tz.rs

1use {
2    async_proto_derive::impl_protocol_for,
3    crate::{
4        Protocol,
5        ReadErrorKind,
6    },
7};
8
9#[derive(Protocol)]
10#[async_proto(internal)]
11struct TzProxy {
12    name: String,
13}
14
15impl TryFrom<TzProxy> for chrono_tz::Tz {
16    type Error = ReadErrorKind;
17
18    fn try_from(TzProxy { name }: TzProxy) -> Result<Self, ReadErrorKind> {
19        name.parse::<Self>().map_err(|e| ReadErrorKind::Custom(e.to_string()))
20    }
21}
22
23impl<'a> From<&'a chrono_tz::Tz> for TzProxy {
24    fn from(tz: &chrono_tz::Tz) -> Self {
25        Self { name: tz.name().to_owned() }
26    }
27}
28
29impl_protocol_for! {
30    #[async_proto(attr(cfg_attr(docsrs, doc(cfg(feature = "chrono-tz")))))]
31    #[async_proto(attr(doc = "A timezone is represented as an [IANA timezone identifier](https://data.iana.org/time-zones/theory.html#naming)."))]
32    #[async_proto(via = TzProxy)]
33    type chrono_tz::Tz;
34}