async_proto/impls/
semver.rs1use {
2 async_proto_derive::impl_protocol_for,
3 crate::{
4 Protocol,
5 ReadErrorKind,
6 },
7};
8
9#[derive(Protocol)]
10#[async_proto(internal)]
11struct IdentifierProxy(String);
12
13impl TryFrom<IdentifierProxy> for semver::Prerelease {
14 type Error = ReadErrorKind;
15
16 fn try_from(IdentifierProxy(s): IdentifierProxy) -> Result<Self, ReadErrorKind> {
17 s.parse::<Self>().map_err(|e| ReadErrorKind::Custom(e.to_string()))
18 }
19}
20
21impl<'a> From<&'a semver::Prerelease> for IdentifierProxy {
22 fn from(prerelease: &semver::Prerelease) -> Self {
23 Self(prerelease.to_string())
24 }
25}
26
27impl TryFrom<IdentifierProxy> for semver::BuildMetadata {
28 type Error = ReadErrorKind;
29
30 fn try_from(IdentifierProxy(s): IdentifierProxy) -> Result<Self, ReadErrorKind> {
31 s.parse::<Self>().map_err(|e| ReadErrorKind::Custom(e.to_string()))
32 }
33}
34
35impl<'a> From<&'a semver::BuildMetadata> for IdentifierProxy {
36 fn from(build: &semver::BuildMetadata) -> Self {
37 Self(build.to_string())
38 }
39}
40
41impl_protocol_for! {
42 #[async_proto(attr(cfg_attr(docsrs, doc(cfg(feature = "semver")))))]
43 struct semver::Version {
44 major: u64,
45 minor: u64,
46 patch: u64,
47 pre: semver::Prerelease,
48 build: semver::BuildMetadata,
49 }
50
51 #[async_proto(attr(cfg_attr(docsrs, doc(cfg(feature = "semver")))))]
52 #[async_proto(via = IdentifierProxy)]
53 type semver::Prerelease;
54
55 #[async_proto(attr(cfg_attr(docsrs, doc(cfg(feature = "semver")))))]
56 #[async_proto(via = IdentifierProxy)]
57 type semver::BuildMetadata;
58}