Change ToCss to take a CssWriter<W>

This more concrete wrapper type can write a prefix the very first time something
is written to it. This allows removing plenty of useless monomorphisations caused
by the former W/SequenceWriter<W> pair of types.
This commit is contained in:
Anthony Ramine 2018-01-22 19:58:01 +01:00
parent 3672856efa
commit cd8f96cc9e
89 changed files with 873 additions and 533 deletions

View file

@ -13,9 +13,9 @@ pub use cssparser::{RGBA, Token, Parser, serialize_identifier, CowRcStr, SourceL
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseErrorKind;
#[allow(unused_imports)] use std::ascii::AsciiExt;
use std::fmt::{self, Debug};
use std::fmt::{self, Debug, Write};
use std::hash;
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
pub mod animated;
pub mod computed;
@ -34,8 +34,9 @@ define_keyword_type!(Auto, "auto");
define_keyword_type!(Normal, "normal");
/// Serialize a normalized value into percentage.
pub fn serialize_percentage<W>(value: CSSFloat, dest: &mut W)
-> fmt::Result where W: fmt::Write
pub fn serialize_percentage<W>(value: CSSFloat, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
(value * 100.).to_css(dest)?;
dest.write_str("%")
@ -109,7 +110,10 @@ impl CustomIdent {
}
impl ToCss for CustomIdent {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
serialize_identifier(&self.0.to_string(), dest)
}
}
@ -180,7 +184,10 @@ impl Parse for KeyframesName {
}
impl ToCss for KeyframesName {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
match *self {
KeyframesName::Ident(ref ident) => ident.to_css(dest),
KeyframesName::QuotedString(ref atom) => atom.to_string().to_css(dest),