diff --git a/src/core.rs b/src/core.rs index cf13ba7..67527eb 100644 --- a/src/core.rs +++ b/src/core.rs @@ -99,18 +99,6 @@ pub trait Resolver<'a, Ctx: 'a + Context>: 'a { fn resolve(self: Rc, address: Address) -> HashResolution<'a, Ctx>; } -/// Trait representing a readable stream used for parsing. -/// -/// See [`Serializer`], [`Factory::deserialize`]. -pub trait Deserializer { - /// Read at most `n` bytes. - fn read_n(&mut self, n: usize) -> &[u8]; - /// Read til the end of the stream. - fn read_all(&mut self) -> &[u8]; - /// See [`Serializer::tell`]. - fn tell(&self) -> usize; -} - /// Short-hand for the type of vaalues returned by [`Factory::deserialize`]. pub type ParseResult<'a, Ctx, F> = Result<>::Mtbl, >::ParseError>; @@ -222,22 +210,6 @@ impl Addresses { } } -/// Extension trait for [Deserializer]s. -pub trait ExtDeserializer { - /// Try to read exactly `N` bytes. - fn read_n_const(&mut self) -> Result<[u8; N], &[u8]>; -} - -impl ExtDeserializer for D { - fn read_n_const(&mut self) -> Result<[u8; N], &[u8]> { - let slice = self.read_n(N); - match slice.try_into() { - Ok(array) => Ok(array), - Err(_) => Err(slice), - } - } -} - struct ResolverOrigin<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> { r_factory: F, r_address: Address, diff --git a/src/core/serialization.rs b/src/core/serialization.rs index 8bdf8d4..da8a98e 100644 --- a/src/core/serialization.rs +++ b/src/core/serialization.rs @@ -24,3 +24,31 @@ impl Serializer for Vec { self.len() } } + +/// Trait representing a readable stream used for parsing. +/// +/// See [`Serializer`], [`Factory::deserialize`]. +pub trait Deserializer { + /// Read at most `n` bytes. + fn read_n(&mut self, n: usize) -> &[u8]; + /// Read til the end of the stream. + fn read_all(&mut self) -> &[u8]; + /// See [`Serializer::tell`]. + fn tell(&self) -> usize; +} + +/// Extension trait for [Deserializer]s. +pub trait ExtDeserializer { + /// Try to read exactly `N` bytes. + fn read_n_const(&mut self) -> Result<[u8; N], &[u8]>; +} + +impl ExtDeserializer for D { + fn read_n_const(&mut self) -> Result<[u8; N], &[u8]> { + let slice = self.read_n(N); + match slice.try_into() { + Ok(array) => Ok(array), + Err(_) => Err(slice), + } + } +}