diff options
author | Xidorn Quan <me@upsuper.org> | 2018-04-29 09:03:31 +1000 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-04-29 03:28:41 +0200 |
commit | eb554044dbd984ed77c4f7bc089e90118ad55857 (patch) | |
tree | 1ec8f6bacb74160f1a8ee4d485274515a02048e4 /components/style_traits/values.rs | |
parent | 26c3aeda97cdb03e0bfd59270439399a664650ff (diff) | |
download | servo-eb554044dbd984ed77c4f7bc089e90118ad55857.tar.gz servo-eb554044dbd984ed77c4f7bc089e90118ad55857.zip |
style: Add SequenceWriter::item_str for writing str items.
This will be used in the next patch for font-variant bitflag types.
Bug: 1434130
Reviewed-by: emilio
MozReview-Commit-ID: 2IvcsnYBNqA
Diffstat (limited to 'components/style_traits/values.rs')
-rw-r--r-- | components/style_traits/values.rs | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/components/style_traits/values.rs b/components/style_traits/values.rs index d6bd05b7b40..481eb1aff6d 100644 --- a/components/style_traits/values.rs +++ b/components/style_traits/values.rs @@ -173,16 +173,10 @@ where Self { inner, separator } } - /// Serialises a CSS value, writing any separator as necessary. - /// - /// The separator is never written before any `item` produces any output, - /// and is written in subsequent calls only if the `item` produces some - /// output on its own again. This lets us handle `Option<T>` fields by - /// just not printing anything on `None`. #[inline] - pub fn item<T>(&mut self, item: &T) -> fmt::Result + fn write_item<F>(&mut self, f: F) -> fmt::Result where - T: ToCss, + F: FnOnce(&mut CssWriter<'b, W>) -> fmt::Result { let old_prefix = self.inner.prefix; if old_prefix.is_none() { @@ -191,7 +185,7 @@ where // to write the separator next time we produce output again. self.inner.prefix = Some(self.separator); } - item.to_css(&mut self.inner)?; + f(self.inner)?; match (old_prefix, self.inner.prefix) { (_, None) => { // This call produced output and cleaned up after itself. @@ -213,6 +207,29 @@ where } Ok(()) } + + /// Serialises a CSS value, writing any separator as necessary. + /// + /// The separator is never written before any `item` produces any output, + /// and is written in subsequent calls only if the `item` produces some + /// output on its own again. This lets us handle `Option<T>` fields by + /// just not printing anything on `None`. + #[inline] + pub fn item<T>(&mut self, item: &T) -> fmt::Result + where + T: ToCss, + { + self.write_item(|inner| item.to_css(inner)) + } + + /// Writes a string as-is (i.e. not escaped or wrapped in quotes) + /// with any separator as necessary. + /// + /// See SequenceWriter::item. + #[inline] + pub fn raw_item(&mut self, item: &str) -> fmt::Result { + self.write_item(|inner| inner.write_str(item)) + } } /// A wrapper type that implements `ToCss` by printing its inner field. |