Skip to main content

Printer

Struct Printer 

Source
pub struct Printer<'a> { /* private fields */ }
Expand description

Output buffer driven by the emit functions in crate::emit.

Implementations§

Source§

impl<'a> Printer<'a>

Source

pub fn new(interner: &'a ThreadedRodeo, src: &'a str) -> Self

Source

pub fn write_str(&mut self, s: &str)

Write s at the current cursor; emits pending indent first.

Source

pub fn write_ident(&mut self, spur: Spur)

Resolve and emit an interned identifier.

Source

pub fn resolve(&self, spur: Spur) -> &str

Resolve an interned string without emitting it; callers re-escape before writing (e.g. string literals).

Source

pub fn newline(&mut self)

Begin a new line. Subsequent writes will be preceded by indent whitespace.

Source

pub fn blank_line(&mut self)

Emit a blank line between sibling items. Idempotent — repeated calls without intervening writes produce at most one blank line, matching the “at most one consecutive blank line” rule. Also no-ops when the cursor is directly inside a freshly-opened brace (style rule: “No blank line at the start of a block”).

Source

pub fn indent(&mut self)

Source

pub fn dedent(&mut self)

Source

pub fn drain_trivia_before(&mut self, offset: u32)

Drain every trivia entry whose start is strictly before offset — these are the comments and blank-line runs that fall before the next AST node.

Source

pub fn drain_trivia_remaining(&mut self)

Drain every remaining trivia entry — used once at end-of-AST to flush any trailing comments past the last item.

Source

pub fn drain_trailing_comment_on_line(&mut self)

Drain // comment trivia that begins on the same source line as the most recently emitted node. The comment is appended inline with two leading spaces; the caller emits the terminating newline.

Call this immediately after mark_emitted_end and before the newline() that ends the line — that ordering keeps the comment glued to the statement/item it follows in source.

Source

pub fn mark_emitted_end(&mut self, byte: u32)

Record that the AST node ending at byte has just been emitted. Used to decide whether a following comment is a trailing same-line one.

Source

pub fn finish(self) -> String

Consume the printer and return the formatted source. Guarantees exactly one trailing newline at EOF.

Auto Trait Implementations§

§

impl<'a> Freeze for Printer<'a>

§

impl<'a> !RefUnwindSafe for Printer<'a>

§

impl<'a> Send for Printer<'a>

§

impl<'a> Sync for Printer<'a>

§

impl<'a> Unpin for Printer<'a>

§

impl<'a> UnsafeUnpin for Printer<'a>

§

impl<'a> !UnwindSafe for Printer<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

§

type Proj<U: 'src> = U

§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.