~tdeo/serde_bare

4f8137c200a6d3a7227469e299b1933369b9c118 — Tadeo Kondrak 11 months ago f894a9d
Remove useless closures
2 files changed, 30 insertions(+), 52 deletions(-)

M src/de.rs
M src/ser.rs
M src/de.rs => src/de.rs +16 -16
@@ 47,7 47,7 @@ where
        V: de::Visitor<'de>,
    {
        let mut buf = [0u8; 1];
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_i8(i8::from_le_bytes(buf))
    }



@@ 57,7 57,7 @@ where
        V: de::Visitor<'de>,
    {
        let mut buf = [0u8; 2];
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_i16(i16::from_le_bytes(buf))
    }



@@ 67,7 67,7 @@ where
        V: de::Visitor<'de>,
    {
        let mut buf = [0u8; 4];
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_i32(i32::from_le_bytes(buf))
    }



@@ 77,7 77,7 @@ where
        V: de::Visitor<'de>,
    {
        let mut buf = [0u8; 8];
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_i64(i64::from_le_bytes(buf))
    }



@@ 88,7 88,7 @@ where
            V: de::Visitor<'de>
        {
            let mut buf = [0u8; 16];
            self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
            self.reader.read_exact(&mut buf).map_err(Error::Io)?;
            visitor.visit_i128(i128::from_le_bytes(buf))
        }
    }


@@ 99,7 99,7 @@ where
        V: de::Visitor<'de>,
    {
        let mut buf = [0u8; 1];
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_u8(u8::from_le_bytes(buf))
    }



@@ 109,7 109,7 @@ where
        V: de::Visitor<'de>,
    {
        let mut buf = [0u8; 2];
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_u16(u16::from_le_bytes(buf))
    }



@@ 119,7 119,7 @@ where
        V: de::Visitor<'de>,
    {
        let mut buf = [0u8; 4];
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_u32(u32::from_le_bytes(buf))
    }



@@ 129,7 129,7 @@ where
        V: de::Visitor<'de>,
    {
        let mut buf = [0u8; 8];
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_u64(u64::from_le_bytes(buf))
    }



@@ 140,7 140,7 @@ where
            V: de::Visitor<'de>
        {
            let mut buf = [0u8; 16];
            self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
            self.reader.read_exact(&mut buf).map_err(Error::Io)?;
            visitor.visit_u128(u128::from_le_bytes(buf))
        }
    }


@@ 151,7 151,7 @@ where
        V: de::Visitor<'de>,
    {
        let mut buf = [0u8; 4];
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_f32(f32::from_le_bytes(buf))
    }



@@ 161,7 161,7 @@ where
        V: de::Visitor<'de>,
    {
        let mut buf = [0u8; 8];
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_f64(f64::from_le_bytes(buf))
    }



@@ 181,7 181,7 @@ where
        let length = <u32 as de::Deserialize>::deserialize(&mut *self)? as usize;
        let mut buf = Vec::with_capacity(length);
        buf.resize(length, 0);
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        let utf8 = str::from_utf8(&buf).map_err(|_| Error::InvalidUtf8)?;
        visitor.visit_str(utf8)
    }


@@ 194,7 194,7 @@ where
        let length = <u32 as de::Deserialize>::deserialize(&mut *self)? as usize;
        let mut buf = Vec::with_capacity(length);
        buf.resize(length, 0);
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        let utf8 = String::from_utf8(buf).map_err(|_| Error::InvalidUtf8)?;
        visitor.visit_string(utf8)
    }


@@ 207,7 207,7 @@ where
        let length = <u32 as de::Deserialize>::deserialize(&mut *self)? as usize;
        let mut buf = Vec::with_capacity(length);
        buf.resize(length, 0);
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_bytes(&buf)
    }



@@ 219,7 219,7 @@ where
        let length = <u32 as de::Deserialize>::deserialize(&mut *self)? as usize;
        let mut buf = Vec::with_capacity(length);
        buf.resize(length, 0);
        self.reader.read_exact(&mut buf).map_err(|e| Error::Io(e))?;
        self.reader.read_exact(&mut buf).map_err(Error::Io)?;
        visitor.visit_byte_buf(buf)
    }


M src/ser.rs => src/ser.rs +14 -36
@@ 33,33 33,25 @@ where

    /// BARE type: i8
    fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error> {
        self.writer
            .write_all(&v.to_le_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(&v.to_le_bytes()).map_err(Error::Io)?;
        Ok(())
    }

    /// BARE type: i16
    fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error> {
        self.writer
            .write_all(&v.to_le_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(&v.to_le_bytes()).map_err(Error::Io)?;
        Ok(())
    }

    /// BARE type: i32
    fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error> {
        self.writer
            .write_all(&v.to_le_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(&v.to_le_bytes()).map_err(Error::Io)?;
        Ok(())
    }

    /// BARE type: i64
    fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> {
        self.writer
            .write_all(&v.to_le_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(&v.to_le_bytes()).map_err(Error::Io)?;
        Ok(())
    }



@@ 68,40 60,32 @@ where
        fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> {
            self.writer
                .write_all(&v.to_le_bytes())
                .map_err(|e| Error::Io(e))?;
                .map_err(Error::Io)?;
            Ok(())
        }
    }

    /// BARE type: u8
    fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
        self.writer
            .write_all(&v.to_le_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(&v.to_le_bytes()).map_err(Error::Io)?;
        Ok(())
    }

    /// BARE type: u16
    fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error> {
        self.writer
            .write_all(&v.to_le_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(&v.to_le_bytes()).map_err(Error::Io)?;
        Ok(())
    }

    /// BARE type: u32
    fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> {
        self.writer
            .write_all(&v.to_le_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(&v.to_le_bytes()).map_err(Error::Io)?;
        Ok(())
    }

    /// BARE type: u64
    fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> {
        self.writer
            .write_all(&v.to_le_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(&v.to_le_bytes()).map_err(Error::Io)?;
        Ok(())
    }



@@ 110,24 94,20 @@ where
        fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> {
            self.writer
                .write_all(&v.to_le_bytes())
                .map_err(|e| Error::Io(e))?;
                .map_err(Error::Io)?;
            Ok(())
        }
    }

    /// BARE type: f32
    fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> {
        self.writer
            .write_all(&v.to_le_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(&v.to_le_bytes()).map_err(Error::Io)?;
        Ok(())
    }

    /// BARE type: f64
    fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error> {
        self.writer
            .write_all(&v.to_le_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(&v.to_le_bytes()).map_err(Error::Io)?;
        Ok(())
    }



@@ 141,9 121,7 @@ where
    fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
        let len: u32 = v.len().try_into().map_err(|_| Error::LengthOverflow)?;
        self.serialize_u32(len)?;
        self.writer
            .write_all(v.as_bytes())
            .map_err(|e| Error::Io(e))?;
        self.writer.write_all(v.as_bytes()).map_err(Error::Io)?;
        Ok(())
    }



@@ 152,7 130,7 @@ where
    fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error> {
        let len: u32 = v.len().try_into().map_err(|_| Error::LengthOverflow)?;
        self.serialize_u32(len)?;
        self.writer.write_all(v).map_err(|e| Error::Io(e))?;
        self.writer.write_all(v).map_err(Error::Io)?;
        Ok(())
    }