diff --git a/Cargo.toml b/Cargo.toml index d50339be..c875d894 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ encoding_rs = "0.8" [dependencies] cssparser-macros = {path = "./macros", version = "0.6"} dtoa-short = "0.3" -itoa = "0.4" +itoa = "1.0" matches = "0.1" phf = {version = "0.8", features = ["macros"]} serde = {version = "1.0", optional = true} diff --git a/src/serializer.rs b/src/serializer.rs index abd50c3d..91fff839 100644 --- a/src/serializer.rs +++ b/src/serializer.rs @@ -6,7 +6,6 @@ use dtoa_short::{self, Notation}; use itoa; use matches::matches; use std::fmt::{self, Write}; -use std::io; use std::str; use super::Token; @@ -340,34 +339,9 @@ macro_rules! impl_tocss_for_int { where W: fmt::Write, { - struct AssumeUtf8(W); - - impl io::Write for AssumeUtf8 { - #[inline] - fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { - // Safety: itoa only emits ASCII, which is also well-formed UTF-8. - debug_assert!(buf.is_ascii()); - self.0 - .write_str(unsafe { str::from_utf8_unchecked(buf) }) - .map_err(|_| io::ErrorKind::Other.into()) - } - - #[inline] - fn write(&mut self, buf: &[u8]) -> io::Result { - self.write_all(buf)?; - Ok(buf.len()) - } - - #[inline] - fn flush(&mut self) -> io::Result<()> { - Ok(()) - } - } - - match itoa::write(AssumeUtf8(dest), *self) { - Ok(_) => Ok(()), - Err(_) => Err(fmt::Error), - } + let mut buf = itoa::Buffer::new(); + let s = buf.format(*self); + dest.write_str(s) } } };