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>

source

pub fn new(dest: &'a mut W, options: PrinterOptions<'a>) -> Self

Create a new Printer wrapping the given destination.

source

pub fn filename(&self) -> &'c str

Returns the current source filename that is being printed.

source

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.

source

pub fn write_char(&mut self, c: char) -> Result<(), PrinterError>

Write a single character to the underlying destination.

source

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.

source

pub fn delim( &mut self, delim: char, ws_before: bool ) -> Result<(), PrinterError>

Writes a delimeter character, followed by whitespace (depending on the minify option). If ws_before is true, then whitespace is also written before the delimeter.

source

pub fn newline(&mut self) -> Result<(), PrinterError>

Writes a newline character followed by indentation. If the minify option is enabled, then nothing is printed.

source

pub fn indent(&mut self)

Increases the current indent level.

source

pub fn dedent(&mut self)

Decreases the current indent level.

source

pub fn indent_by(&mut self, amt: u8)

Increases the current indent level by the given number of characters.

source

pub fn dedent_by(&mut self, amt: u8)

Decreases the current indent level by the given number of characters.

source

pub fn is_nested(&self) -> bool

Returns whether the indent level is greater than one.

source

pub fn add_mapping(&mut self, loc: Location)

Available on crate feature sourcemap only.

Adds a mapping to the source map, if any.

source

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.

source

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§

source§

impl<'a, 'b, 'c, W: Write + Sized> Write for Printer<'a, 'b, 'c, W>

source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

§

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>where 'b: 'a,

§

impl<'a, 'b, 'c, W> !UnwindSafe for Printer<'a, 'b, 'c, W>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.