Macroize @font-face descriptor definitions

This commit is contained in:
Simon Sapin 2017-01-31 18:07:06 +01:00
parent 2b83d844da
commit 4bcae573b3
3 changed files with 89 additions and 57 deletions

View file

@ -24,6 +24,21 @@ pub trait ToCss {
}
}
/// Marker trait to automatically implement ToCss for Vec<T>.
pub trait CommaSeparated {}
impl<T> ToCss for Vec<T> where T: ToCss + CommaSeparated {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut iter = self.iter();
iter.next().unwrap().to_css(dest)?;
for item in iter {
dest.write_str(", ")?;
item.to_css(dest)?;
}
Ok(())
}
}
impl ToCss for Au {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{}px", self.to_f64_px())