Move utf8 encode to where it is used
This commit is contained in:
parent
726eea9a97
commit
2e9cc6e98a
@ -112,6 +112,7 @@ pub mod value;
|
||||
mod from_primitive;
|
||||
mod ignored_any;
|
||||
mod impls;
|
||||
mod utf8;
|
||||
|
||||
pub use self::ignored_any::IgnoredAny;
|
||||
|
||||
@ -1049,7 +1050,7 @@ pub trait Visitor<'de>: Sized {
|
||||
fn visit_char<E>(self, v: char) -> Result<Self::Value, E>
|
||||
where E: Error
|
||||
{
|
||||
self.visit_str(::utils::encode_utf8(v).as_str())
|
||||
self.visit_str(utf8::encode(v).as_str())
|
||||
}
|
||||
|
||||
/// Deserialize a `&str` into a `Value`.
|
||||
|
@ -1,5 +1,3 @@
|
||||
//! Private utility functions
|
||||
|
||||
const TAG_CONT: u8 = 0b1000_0000;
|
||||
const TAG_TWO_B: u8 = 0b1100_0000;
|
||||
const TAG_THREE_B: u8 = 0b1110_0000;
|
||||
@ -9,7 +7,7 @@ const MAX_TWO_B: u32 = 0x800;
|
||||
const MAX_THREE_B: u32 = 0x10000;
|
||||
|
||||
#[inline]
|
||||
pub fn encode_utf8(c: char) -> EncodeUtf8 {
|
||||
pub fn encode(c: char) -> Encode {
|
||||
let code = c as u32;
|
||||
let mut buf = [0; 4];
|
||||
let pos = if code < MAX_ONE_B {
|
||||
@ -31,18 +29,18 @@ pub fn encode_utf8(c: char) -> EncodeUtf8 {
|
||||
buf[3] = (code & 0x3F) as u8 | TAG_CONT;
|
||||
0
|
||||
};
|
||||
EncodeUtf8 {
|
||||
Encode {
|
||||
buf: buf,
|
||||
pos: pos,
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EncodeUtf8 {
|
||||
pub struct Encode {
|
||||
buf: [u8; 4],
|
||||
pos: usize,
|
||||
}
|
||||
|
||||
impl EncodeUtf8 {
|
||||
impl Encode {
|
||||
// FIXME: use this from_utf8_unchecked, since we know it can never fail
|
||||
pub fn as_str(&self) -> &str {
|
||||
::core::str::from_utf8(&self.buf[self.pos..]).unwrap()
|
@ -93,7 +93,6 @@ pub use de::{Deserialize, Deserializer};
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod utils;
|
||||
|
||||
pub mod de;
|
||||
pub mod ser;
|
||||
|
Loading…
x
Reference in New Issue
Block a user