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,
handle_css_module: bool
) -> Result<(), PrinterError>
pub fn write_ident( &mut self, ident: &str, handle_css_module: bool ) -> 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.
Trait Implementations§
Auto Trait Implementations§
impl<'a, 'b, 'c, W> Freeze for Printer<'a, 'b, 'c, W>
impl<'a, 'b, 'c, W> RefUnwindSafe for Printer<'a, 'b, 'c, W>where
W: RefUnwindSafe,
impl<'a, 'b, 'c, W> Send for Printer<'a, 'b, 'c, W>where
W: Send,
impl<'a, 'b, 'c, W> Sync for Printer<'a, 'b, 'c, W>where
W: Sync,
impl<'a, 'b, 'c, W> Unpin for Printer<'a, 'b, 'c, W>
impl<'a, 'b, 'c, W> !UnwindSafe for Printer<'a, 'b, 'c, W>
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more