Struct expander::Expander

source ·
pub struct Expander { /* private fields */ }
Expand description

Expander to replace a tokenstream by a include to a file

Implementations§

source§

impl Expander

source

pub fn new(filename_base: impl AsRef<str>) -> Self

Create a new expander.

The filename_base will be expanded to {filename_base}-{digest}.rs in order to dismabiguate .

source

pub fn add_comment(self, comment: impl Into<Option<String>>) -> Self

Add a header comment.

source

pub fn fmt(self, edition: impl Into<Edition>) -> Self

Format the resulting file, for readability.

source

pub fn fmt_full( self, channel: impl Into<Channel>, edition: impl Into<Edition>, allow_failure: bool, ) -> Self

Format the resulting file, for readability.

Allows to specify channel and if a failure is fatal in addition.

Note: Calling [fn fmt(..)] afterwards will override settings given.

source

pub fn dry(self, dry: bool) -> Self

Do not modify the provided tokenstream.

source

pub fn verbose(self, verbose: bool) -> Self

Print the path of the generated file to stderr during the proc-macro invocation.

source

pub fn maybe_write_to_out_dir( self, tokens: impl Into<Result<TokenStream, Error>>, ) -> Result<Result<TokenStream>, Error>

Create a file with filename under env!("OUT_DIR") if it’s not an Err(_).

source

pub fn write_to_out_dir(self, tokens: TokenStream) -> Result<TokenStream, Error>

Create a file with filename under env!("OUT_DIR").

source

pub fn maybe_write_to( self, maybe_tokens: impl Into<Result<TokenStream, Error>>, dest_dir: &Path, ) -> Result<Result<TokenStream>, Error>

Create a file with filename at dest if it’s not an Err(_).

source

pub fn write_to( self, tokens: TokenStream, dest_dir: &Path, ) -> Result<TokenStream, Error>

Create a file with self.filename in dest_dir.

Trait Implementations§

source§

impl Debug for Expander

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Expander

source§

fn default() -> Expander

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

Auto Trait Implementations§

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.