Skip to content

Commit 007e687

Browse files
author
Louis Dupré Bertoni
committed
Update itoa to 1.0
1 parent 7c9854e commit 007e687

File tree

2 files changed

+4
-30
lines changed

2 files changed

+4
-30
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ encoding_rs = "0.8"
2222
[dependencies]
2323
cssparser-macros = {path = "./macros", version = "0.6"}
2424
dtoa-short = "0.3"
25-
itoa = "0.4"
25+
itoa = "1.0"
2626
matches = "0.1"
2727
phf = {version = "0.8", features = ["macros"]}
2828
serde = {version = "1.0", optional = true}

src/serializer.rs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use dtoa_short::{self, Notation};
66
use itoa;
77
use matches::matches;
88
use std::fmt::{self, Write};
9-
use std::io;
109
use std::str;
1110

1211
use super::Token;
@@ -340,34 +339,9 @@ macro_rules! impl_tocss_for_int {
340339
where
341340
W: fmt::Write,
342341
{
343-
struct AssumeUtf8<W: fmt::Write>(W);
344-
345-
impl<W: fmt::Write> io::Write for AssumeUtf8<W> {
346-
#[inline]
347-
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
348-
// Safety: itoa only emits ASCII, which is also well-formed UTF-8.
349-
debug_assert!(buf.is_ascii());
350-
self.0
351-
.write_str(unsafe { str::from_utf8_unchecked(buf) })
352-
.map_err(|_| io::ErrorKind::Other.into())
353-
}
354-
355-
#[inline]
356-
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
357-
self.write_all(buf)?;
358-
Ok(buf.len())
359-
}
360-
361-
#[inline]
362-
fn flush(&mut self) -> io::Result<()> {
363-
Ok(())
364-
}
365-
}
366-
367-
match itoa::write(AssumeUtf8(dest), *self) {
368-
Ok(_) => Ok(()),
369-
Err(_) => Err(fmt::Error),
370-
}
342+
let mut buf = itoa::Buffer::new();
343+
let s = buf.format(*self);
344+
dest.write_str(s)
371345
}
372346
}
373347
};

0 commit comments

Comments
 (0)