Skip to main content

Code

Struct Code 

Source
pub struct Code<L> { /* private fields */ }
Expand description

Generated code of language L, written a line at a time at the current depth.

Implementations§

Source§

impl<L: Blocks + Comments + Literals> Code<L>

Source

pub fn new() -> Self

An empty file.

Source

pub fn starting(text: impl Into<String>) -> Self

A file starting with text (its header, say) as written.

Source

pub fn str(&self, text: &str) -> String

A string literal of the language.

Source

pub fn line(&mut self, text: impl AsRef<str>) -> &mut Self

One line at the current depth.

Source

pub fn blank(&mut self) -> &mut Self

An empty line.

Source

pub fn doc(&mut self, text: impl AsRef<str>) -> &mut Self

A doc comment on what follows.

Source

pub fn open(&mut self, head: impl AsRef<str>) -> &mut Self

A block after head, and what follows one level deeper.

Source

pub fn close(&mut self, tail: &str) -> &mut Self

The innermost block closed, then tail.

Source

pub fn finish(self) -> String

The code written.

Trait Implementations§

Source§

impl<L: Blocks + Comments + Literals> Default for Code<L>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<L> Freeze for Code<L>
where PhantomData<L>: Freeze,

§

impl<L> RefUnwindSafe for Code<L>

§

impl<L> Send for Code<L>
where PhantomData<L>: Send,

§

impl<L> Sync for Code<L>
where PhantomData<L>: Sync,

§

impl<L> Unpin for Code<L>
where PhantomData<L>: Unpin,

§

impl<L> UnsafeUnpin for Code<L>

§

impl<L> UnwindSafe for Code<L>

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.

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.