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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
use super::*; impl From<u8> for ZomeId { fn from(a: u8) -> Self { Self(a) } } impl From<ZomeId> for u8 { fn from(a: ZomeId) -> Self { a.0 } } impl std::fmt::Display for ZomeId { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } } impl From<u8> for EntryDefIndex { fn from(a: u8) -> Self { Self(a) } } #[derive(PartialEq, Eq, Debug, Clone)] pub struct WrongHeaderError(pub String); impl std::fmt::Display for WrongHeaderError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "Tried to unwrap a Header to the wrong variant") } } impl std::error::Error for WrongHeaderError {} impl TryFrom<Header> for Update { type Error = WrongHeaderError; fn try_from(value: Header) -> Result<Self, Self::Error> { match value { Header::Update(h) => Ok(h), _ => Err(WrongHeaderError(format!("{:?}", value))), } } } impl<'a> TryFrom<&'a Header> for &'a Update { type Error = WrongHeaderError; fn try_from(value: &'a Header) -> Result<Self, Self::Error> { match value { Header::Update(h) => Ok(h), _ => Err(WrongHeaderError(format!("{:?}", value))), } } } impl TryFrom<Header> for Delete { type Error = WrongHeaderError; fn try_from(value: Header) -> Result<Self, Self::Error> { match value { Header::Delete(h) => Ok(h), _ => Err(WrongHeaderError(format!("{:?}", value))), } } } impl<'a> TryFrom<&'a Header> for &'a Delete { type Error = WrongHeaderError; fn try_from(value: &'a Header) -> Result<Self, Self::Error> { match value { Header::Delete(h) => Ok(h), _ => Err(WrongHeaderError(format!("{:?}", value))), } } } impl TryFrom<Header> for CreateLink { type Error = WrongHeaderError; fn try_from(value: Header) -> Result<Self, Self::Error> { match value { Header::CreateLink(h) => Ok(h), _ => Err(WrongHeaderError(format!("{:?}", value))), } } } impl<'a> TryFrom<&'a Header> for &'a CreateLink { type Error = WrongHeaderError; fn try_from(value: &'a Header) -> Result<Self, Self::Error> { match value { Header::CreateLink(h) => Ok(h), _ => Err(WrongHeaderError(format!("{:?}", value))), } } } impl TryFrom<Header> for DeleteLink { type Error = WrongHeaderError; fn try_from(value: Header) -> Result<Self, Self::Error> { match value { Header::DeleteLink(h) => Ok(h), _ => Err(WrongHeaderError(format!("{:?}", value))), } } } impl<'a> TryFrom<&'a Header> for &'a DeleteLink { type Error = WrongHeaderError; fn try_from(value: &'a Header) -> Result<Self, Self::Error> { match value { Header::DeleteLink(h) => Ok(h), _ => Err(WrongHeaderError(format!("{:?}", value))), } } }