~tdeo/serde_bare

65fd51b93d579c2c4acb18d210b0e1232332e11b — Tadeo Kondrak 11 months ago 4f8137c
Fix char support

Previously, this would call the visitor's u32 functions.
2 files changed, 5 insertions(+), 1 deletions(-)

M src/de.rs
M src/error.rs
M src/de.rs => src/de.rs +3 -1
@@ 1,6 1,7 @@
use crate::error::Error;
use serde::de;
use std::{
    convert::TryInto,
    i16, i32, i64, i8,
    io::{Cursor, Read},
    str, u16, u32, u64, u8,


@@ 170,7 171,8 @@ where
    where
        V: de::Visitor<'de>,
    {
        self.deserialize_u32(visitor)
        let codepoint = <u32 as de::Deserialize>::deserialize(&mut *self)?;
        visitor.visit_char(codepoint.try_into().map_err(|_| Error::InvalidChar)?)
    }

    /// BARE type: string

M src/error.rs => src/error.rs +2 -0
@@ 15,6 15,7 @@ pub enum Error {
    IdentifierUnsupported,

    InvalidUtf8,
    InvalidChar,

    LengthOverflow,
    MapLengthRequired,


@@ 40,6 41,7 @@ impl Display for Error {
            Error::AnyUnsupported => formatter.write_str("BARE does not support any"),
            Error::IdentifierUnsupported => formatter.write_str("BARE does not support identifier"),
            Error::InvalidUtf8 => formatter.write_str("invalid utf-8 in string"),
            Error::InvalidChar => formatter.write_str("invalid unicode codepoint in char"),
            Error::LengthOverflow => formatter.write_str("length above u32::MAX"),
            Error::MapLengthRequired => formatter.write_str("map length required"),
        }