Skip to content

Commit 9201560

Browse files
Louis Dupré Bertoniemilio
Louis Dupré Bertoni
authored andcommitted
Update itoa to 1.0
1 parent 6865fd0 commit 9201560

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed

Cargo.toml

+1-1
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.10", features = ["macros"]}
2828
serde = {version = "1.0", optional = true}

src/serializer.rs

+2-29
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;
@@ -342,34 +341,8 @@ macro_rules! impl_tocss_for_int {
342341
where
343342
W: fmt::Write,
344343
{
345-
struct AssumeUtf8<W: fmt::Write>(W);
346-
347-
impl<W: fmt::Write> io::Write for AssumeUtf8<W> {
348-
#[inline]
349-
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
350-
// Safety: itoa only emits ASCII, which is also well-formed UTF-8.
351-
debug_assert!(buf.is_ascii());
352-
self.0
353-
.write_str(unsafe { str::from_utf8_unchecked(buf) })
354-
.map_err(|_| io::ErrorKind::Other.into())
355-
}
356-
357-
#[inline]
358-
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
359-
self.write_all(buf)?;
360-
Ok(buf.len())
361-
}
362-
363-
#[inline]
364-
fn flush(&mut self) -> io::Result<()> {
365-
Ok(())
366-
}
367-
}
368-
369-
match itoa::write(AssumeUtf8(dest), *self) {
370-
Ok(_) => Ok(()),
371-
Err(_) => Err(fmt::Error),
372-
}
344+
let mut buf = itoa::Buffer::new();
345+
dest.write_str(buf.format(*self))
373346
}
374347
}
375348
};

0 commit comments

Comments
 (0)