1 #![rustfmt::skip] 2 /// @generated rust packets from test. 3 use bytes::{Buf, BufMut, Bytes, BytesMut}; 4 use std::convert::{TryFrom, TryInto}; 5 use std::cell::Cell; 6 use std::fmt; 7 use std::result::Result; 8 use pdl_runtime::{DecodeError, EncodeError, Packet}; 9 /// Private prevents users from creating arbitrary scalar values 10 /// in situations where the value needs to be validated. 11 /// Users can freely deref the value, but only the backend 12 /// may create it. 13 #[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] 14 pub struct Private<T>(T); 15 impl<T> std::ops::Deref for Private<T> { 16 type Target = T; deref(&self) -> &Self::Target17 fn deref(&self) -> &Self::Target { 18 &self.0 19 } 20 } 21 impl<T: std::fmt::Debug> std::fmt::Debug for Private<T> { fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 23 T::fmt(&self.0, f) 24 } 25 } 26 #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] 27 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 28 #[cfg_attr(feature = "serde", serde(from = "u32", into = "u32"))] 29 pub struct ExactSize(u32); 30 impl From<&ExactSize> for u32 { from(value: &ExactSize) -> u3231 fn from(value: &ExactSize) -> u32 { 32 value.0 33 } 34 } 35 impl From<ExactSize> for u32 { from(value: ExactSize) -> u3236 fn from(value: ExactSize) -> u32 { 37 value.0 38 } 39 } 40 impl From<u32> for ExactSize { from(value: u32) -> Self41 fn from(value: u32) -> Self { 42 ExactSize(value) 43 } 44 } 45 #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] 46 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 47 #[cfg_attr(feature = "serde", serde(try_from = "u32", into = "u32"))] 48 pub struct TruncatedSize(u32); 49 impl From<&TruncatedSize> for u32 { from(value: &TruncatedSize) -> u3250 fn from(value: &TruncatedSize) -> u32 { 51 value.0 52 } 53 } 54 impl From<TruncatedSize> for u32 { from(value: TruncatedSize) -> u3255 fn from(value: TruncatedSize) -> u32 { 56 value.0 57 } 58 } 59 impl TryFrom<u32> for TruncatedSize { 60 type Error = u32; try_from(value: u32) -> Result<Self, Self::Error>61 fn try_from(value: u32) -> Result<Self, Self::Error> { 62 if value > 0xff_ffff { Err(value) } else { Ok(TruncatedSize(value)) } 63 } 64 } 65