Struct lightningcss::printer::Printer
source · pub struct Printer<'a, 'b, 'c, W> { /* private fields */ }
Expand description
A Printer
represents a destination to output serialized CSS, as used in
the ToCss trait. It can wrap any destination that
implements std::fmt::Write, such as a String.
A Printer
keeps track of the current line and column position, and uses
this to generate a source map if provided in the options.
Printer
also includes helper functions that assist with writing output
that respects options such as minify
, and css_modules
.
Implementations§
source§impl<'a, 'b, 'c, W: Write + Sized> Printer<'a, 'b, 'c, W>
impl<'a, 'b, 'c, W: Write + Sized> Printer<'a, 'b, 'c, W>
sourcepub fn new(dest: &'a mut W, options: PrinterOptions<'a>) -> Self
pub fn new(dest: &'a mut W, options: PrinterOptions<'a>) -> Self
Create a new Printer wrapping the given destination.
sourcepub fn write_str(&mut self, s: &str) -> Result<(), PrinterError>
pub fn write_str(&mut self, s: &str) -> Result<(), PrinterError>
Writes a raw string to the underlying destination.
NOTE: Is is assumed that the string does not contain any newline characters. If such a string is written, it will break source maps.
sourcepub fn write_char(&mut self, c: char) -> Result<(), PrinterError>
pub fn write_char(&mut self, c: char) -> Result<(), PrinterError>
Write a single character to the underlying destination.
sourcepub fn whitespace(&mut self) -> Result<(), PrinterError>
pub fn whitespace(&mut self) -> Result<(), PrinterError>
Writes a single whitespace character, unless the minify
option is enabled.
Use write_char
instead if you wish to force a space character to be written,
regardless of the minify
option.
sourcepub fn delim(
&mut self,
delim: char,
ws_before: bool
) -> Result<(), PrinterError>
pub fn delim( &mut self, delim: char, ws_before: bool ) -> Result<(), PrinterError>
Writes a delimiter character, followed by whitespace (depending on the minify
option).
If ws_before
is true, then whitespace is also written before the delimiter.
sourcepub fn newline(&mut self) -> Result<(), PrinterError>
pub fn newline(&mut self) -> Result<(), PrinterError>
Writes a newline character followed by indentation.
If the minify
option is enabled, then nothing is printed.
sourcepub fn indent_by(&mut self, amt: u8)
pub fn indent_by(&mut self, amt: u8)
Increases the current indent level by the given number of characters.
sourcepub fn dedent_by(&mut self, amt: u8)
pub fn dedent_by(&mut self, amt: u8)
Decreases the current indent level by the given number of characters.
sourcepub fn add_mapping(&mut self, loc: Location)
Available on crate feature sourcemap
only.
pub fn add_mapping(&mut self, loc: Location)
sourcemap
only.Adds a mapping to the source map, if any.
sourcepub fn write_ident(&mut self, ident: &str) -> Result<(), PrinterError>
pub fn write_ident(&mut self, ident: &str) -> Result<(), PrinterError>
Writes a CSS identifier to the underlying destination, escaping it
as appropriate. If the css_modules
option was enabled, then a hash
is added, and the mapping is added to the CSS module.
sourcepub fn error(
&self,
kind: PrinterErrorKind,
loc: Location
) -> Error<PrinterErrorKind>
pub fn error( &self, kind: PrinterErrorKind, loc: Location ) -> Error<PrinterErrorKind>
Returns an error of the given kind at the provided location in the current source file.