Skip to main content

async_proto/impls/
os_info.rs

1use {
2    async_proto_derive::impl_protocol_for,
3    crate::{
4        Protocol,
5        ReadErrorKind,
6        WriteErrorKind,
7    },
8};
9
10#[derive(Protocol)]
11#[async_proto(internal)]
12struct TypeProxy(String);
13
14impl TryFrom<TypeProxy> for os_info::Type {
15    type Error = ReadErrorKind;
16
17    fn try_from(TypeProxy(s): TypeProxy) -> Result<Self, Self::Error> {
18        serde_plain::from_str(&s).map_err(|e| ReadErrorKind::Custom(e.to_string()))
19    }
20}
21
22impl<'a> TryFrom<&'a os_info::Type> for TypeProxy {
23    type Error = WriteErrorKind;
24
25    fn try_from(ty: &os_info::Type) -> Result<Self, Self::Error> {
26        Ok(Self(serde_plain::to_string(ty).map_err(|e| WriteErrorKind::Custom(e.to_string()))?))
27    }
28}
29
30impl_protocol_for! {
31    #[async_proto(attr(cfg_attr(docsrs, doc(cfg(feature = "os_info")))))]
32    #[async_proto(attr(doc = "An OS type is represented as its enum variant name."))]
33    #[async_proto(via = TypeProxy)]
34    type os_info::Type;
35
36    #[async_proto(attr(cfg_attr(docsrs, doc(cfg(feature = "os_info")))))]
37    enum os_info::Version {
38        Unknown,
39        Semantic(u64, u64, u64),
40        Rolling(Option<String>),
41        Custom(String),
42    }
43}