Replace write! with to_css and write_str in some ToCss impls

This commit is contained in:
Xidorn Quan 2017-08-20 17:11:51 +10:00
parent c1b196b7cb
commit 7e92c15e00
11 changed files with 58 additions and 42 deletions

View file

@ -36,6 +36,22 @@ define_keyword_type!(None_, "none");
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
{
(value * 100.).to_css(dest)?;
dest.write_str("%")
}
/// Serialize a value with given unit into dest.
pub fn serialize_dimension<W>(value: CSSFloat, unit: &str, dest: &mut W)
-> fmt::Result where W: fmt::Write
{
value.to_css(dest)?;
dest.write_str(unit)
}
/// Convenience void type to disable some properties and values through types.
#[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))]
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]