Skip to content

Update itoa to 1.0 #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cssparser"
version = "0.29.3"
version = "0.29.4"
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]

description = "Rust implementation of CSS Syntax Level 3"
Expand All @@ -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.10", features = ["macros"]}
serde = {version = "1.0", optional = true}
Expand Down
31 changes: 2 additions & 29 deletions src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -342,34 +341,8 @@ macro_rules! impl_tocss_for_int {
where
W: fmt::Write,
{
struct AssumeUtf8<W: fmt::Write>(W);

impl<W: fmt::Write> io::Write for AssumeUtf8<W> {
#[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<usize> {
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();
dest.write_str(buf.format(*self))
}
}
};
Expand Down