a_deserialize inlining

This commit is contained in:
AF 2023-06-30 22:27:31 +00:00
parent d330a1e66e
commit 4f13bb73ca
4 changed files with 8 additions and 7 deletions

View File

@ -21,7 +21,7 @@ pub trait Atomic: 'static + Send + Sync + Send + Clone + Serializable {
/// Equivalent of [`Factory::ParseError`]. /// Equivalent of [`Factory::ParseError`].
type AParseError: Error; type AParseError: Error;
/// Static equivalent of [`Factory::deserialize`]. /// Static equivalent of [`Factory::deserialize`].
fn a_deserialize(deserializer: &mut dyn Deserializer) -> AParseResult<Self>; fn a_deserialize(deserializer: impl Inlining) -> AParseResult<Self>;
/// Static equivalent of [`Factory::extend`]. /// Static equivalent of [`Factory::extend`].
fn a_extend(self, tail: &[u8]) -> AParseResult<Self>; fn a_extend(self, tail: &[u8]) -> AParseResult<Self>;
} }

View File

@ -37,8 +37,9 @@ impl From<&[u8]> for IntParseError {
impl Atomic for u64 { impl Atomic for u64 {
type AParseError = IntParseError; type AParseError = IntParseError;
fn a_deserialize(deserializer: &mut dyn Deserializer) -> AParseResult<Self> { fn a_deserialize(deserializer: impl Inlining) -> AParseResult<Self> {
Ok(u64::from_le_bytes(deserializer.read_n_const::<8>()?)) let (n, _) = deserializer.iread_n_const::<8>(|slice| IntParseError::from(slice))?;
Ok(u64::from_le_bytes(n))
} }
fn a_extend(self, tail: &[u8]) -> AParseResult<Self> { fn a_extend(self, tail: &[u8]) -> AParseResult<Self> {

View File

@ -44,8 +44,8 @@ impl From<&[u8]> for BooleanParseError {
impl Atomic for bool { impl Atomic for bool {
type AParseError = BooleanParseError; type AParseError = BooleanParseError;
fn a_deserialize(deserializer: &mut dyn Deserializer) -> AParseResult<Self> { fn a_deserialize(deserializer: impl Inlining) -> AParseResult<Self> {
let byte = deserializer.read_n_const::<1>()?; let (byte, _) = deserializer.iread_n_const::<1>(|slice| BooleanParseError::from(slice))?;
match byte[0] { match byte[0] {
0 => Ok(false), 0 => Ok(false),
1 => Ok(true), 1 => Ok(true),

View File

@ -31,8 +31,8 @@ impl Serializable for Plain {
impl Atomic for Plain { impl Atomic for Plain {
type AParseError = PlainParseError; type AParseError = PlainParseError;
fn a_deserialize(deserializer: &mut dyn Deserializer) -> AParseResult<Self> { fn a_deserialize(deserializer: impl Inlining) -> AParseResult<Self> {
Ok(Plain::from_slice(deserializer.read_all())) Ok(deserializer.iread_all(Plain::from_slice))
} }
fn a_extend(mut self, tail: &[u8]) -> AParseResult<Self> { fn a_extend(mut self, tail: &[u8]) -> AParseResult<Self> {