pub struct Printer<'a, 'c, W, S: SourceMap = ()> { /* 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 one is provided.
Printer also includes helper functions that assist with writing output
that respects options such as minify, and css_modules.
Implementations§
Source§impl<'a, 'c, W: Write + Sized, S: SourceMap> Printer<'a, 'c, W, S>
impl<'a, 'c, W: Write + Sized, S: SourceMap> Printer<'a, 'c, W, S>
Sourcepub fn new(dest: &'a mut W, options: PrinterOptions<'a, S>) -> Self
Available on crate feature custom_sourcemap only.
pub fn new(dest: &'a mut W, options: PrinterOptions<'a, S>) -> Self
custom_sourcemap only.Create a new Printer wrapping the given 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 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.
Sourcepub fn add_mapping(&mut self, loc: Location)
Available on crate feature custom_sourcemap only.
pub fn add_mapping(&mut self, loc: Location)
custom_sourcemap only.Adds a mapping to the source map, if any.
Trait Implementations§
Source§impl<'a, 'c, W: Write + Sized, S: SourceMap> PrinterTrait for Printer<'a, 'c, W, S>
impl<'a, 'c, W: Write + Sized, S: SourceMap> PrinterTrait for Printer<'a, 'c, W, S>
fn options(&self) -> &PrinterOptions<'_>
fn filename(&self) -> &str
fn whitespace(&mut self) -> Result<(), PrinterError>
fn delim(&mut self, c: char, ws_before: bool) -> Result<(), PrinterError>
fn newline(&mut self) -> Result<(), PrinterError>
Source§fn add_mapping(&mut self, loc: Location)
fn add_mapping(&mut self, loc: Location)
custom_sourcemap only.fn indent(&mut self)
fn dedent(&mut self)
fn indent_by(&mut self, amt: u8)
fn dedent_by(&mut self, amt: u8)
fn write_ident( &mut self, ident: &str, handle_css_module: bool, ) -> Result<(), PrinterError>
fn write_dashed_ident( &mut self, ident: &str, is_declaration: bool, ) -> Result<(), PrinterError>
fn without_css_module<T, E>( &mut self, f: impl FnOnce(&mut Self) -> Result<T, E>, ) -> Result<T, E>
fn error( &self, kind: PrinterErrorKind, loc: Location, ) -> Error<PrinterErrorKind>
Auto Trait Implementations§
impl<'a, 'c, W, S = ()> !UnwindSafe for Printer<'a, 'c, W, S>
impl<'a, 'c, W, S> Forget for Printer<'a, 'c, W, S>
impl<'a, 'c, W, S> Freeze for Printer<'a, 'c, W, S>
impl<'a, 'c, W, S> Move for Printer<'a, 'c, W, S>
impl<'a, 'c, W, S> RefUnwindSafe for Printer<'a, 'c, W, S>
impl<'a, 'c, W, S> Send for Printer<'a, 'c, W, S>
impl<'a, 'c, W, S> Sync for Printer<'a, 'c, W, S>
impl<'a, 'c, W, S> Unpin for Printer<'a, 'c, W, S>
impl<'a, 'c, W, S> UnsafeUnpin for Printer<'a, 'c, W, S>
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§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