diff options
Diffstat (limited to 'users')
-rw-r--r-- | users/Profpatsch/netencode/netencode.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/users/Profpatsch/netencode/netencode.rs b/users/Profpatsch/netencode/netencode.rs index c8c631689a02..e15cd8b38327 100644 --- a/users/Profpatsch/netencode/netencode.rs +++ b/users/Profpatsch/netencode/netencode.rs @@ -604,6 +604,24 @@ pub mod dec { fn dec(u: U<'a>) -> Result<Self::A, DecodeError>; } + pub struct AnyT; + pub struct AnyU; + + // impl Decoder for AnyT { + // type A = T; + // fn dec(u: U) -> Result<Self::A, DecodeError> { + // // TODO: implement + // parse::u_into_t(u) + // } + // } + + impl<'a> Decoder<'a> for AnyU { + type A = U<'a>; + fn dec(u: U<'a>) -> Result<Self::A, DecodeError> { + Ok(u) + } + } + pub struct ScalarAsBytes; impl<'a> Decoder<'a> for ScalarAsBytes { @@ -637,4 +655,12 @@ pub mod dec { } } } + + fn dec_u(b: &[u8]) -> Result<U, DecodeError> { + match parse::u_u(b) { + Ok((b"", u)) => Ok(u), + Ok((rest, _)) => Err(DecodeError(format!("Cannot decode nested U, it contains trailing bytes"))), + Err(err) => Err(DecodeError(format!("Cannot decode nested U bytes: {:?}", err))), + } + } } |