diff --git a/users/Profpatsch/netencode/netencode.rs b/users/Profpatsch/netencode/netencode.rs index c8c631689..e15cd8b38 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; } + pub struct AnyT; + pub struct AnyU; + + // impl Decoder for AnyT { + // type A = T; + // fn dec(u: U) -> Result { + // // TODO: implement + // parse::u_into_t(u) + // } + // } + + impl<'a> Decoder<'a> for AnyU { + type A = U<'a>; + fn dec(u: U<'a>) -> Result { + Ok(u) + } + } + pub struct ScalarAsBytes; impl<'a> Decoder<'a> for ScalarAsBytes { @@ -637,4 +655,12 @@ pub mod dec { } } } + + fn dec_u(b: &[u8]) -> Result { + 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))), + } + } }