Struct Module

Source
pub struct Module {
    pub code: TokenStream,
    pub usings: BTreeSet<String>,
    pub modules: BTreeMap<String, Module>,
}
Expand description

Manages the code that is generated for a specific module.

This type stores the generated code, the related using directives as well as any sub-module for a specific module generated by the code generator.

Fields§

§code: TokenStream

The actual code that is manages by this module.

§usings: BTreeSet<String>

A set of using directives this module needs.

§modules: BTreeMap<String, Module>

A map of sub-modules contained inside this module.

Implementations§

Source§

impl Module

Source

pub fn append(&mut self, code: TokenStream) -> &mut Self

Append the passed code to this module code.

Source

pub fn prepend(&mut self, code: TokenStream) -> &mut Self

Prepend the passed code to this module code.

Source

pub fn usings<I>(&mut self, usings: I) -> &mut Self
where I: IntoIterator, I::Item: ToString,

Add using directives to the set of this module.

Source

pub fn module<T>(&self, ident: T) -> Option<&Module>
where T: AsRef<str>,

Get a reference to a sub-module identified by the passed ident.

If the module does not exist None is returned.

Source

pub fn module_mut<T>(&mut self, ident: T) -> &mut Module
where T: Into<String>,

Get a mutable reference to a sub-module identified by the passed ident.

If the module does not exist it will be created.

Source

pub fn to_code(&self, tokens: &mut TokenStream, sub_modules: SubModules)

Write the module to the passed token stream.

This method writes the current module to the passed token stream. The sub_modules parameter defines how the sub-modules of this module will be rendered.

Source

pub fn write_to_files<P>(&self, directory: P) -> Result<(), IoError>
where P: AsRef<Path>,

Write the code of the current module to the passed directory.

This will split up the current module into it’s sub modules and writes them to the passed directory. Each sub-module is written to it’s own module file.

§Errors

Returns an IoError if writing a module to a file failed.

Source

pub fn write_to_files_with<F, E>(&self, f: F) -> Result<(), E>
where F: FnMut(&Module, &Path) -> Result<(), E>,

Write the code of the different sub-modules by using the passed function f.

This will split up the current module into it’s sub modules and passes the generated code for each module to the passed function f.

§Errors

Forwards the error raised by f.

Trait Implementations§

Source§

impl Debug for Module

Source§

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

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

impl Default for Module

Source§

fn default() -> Module

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

impl ToTokens for Module

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Write self to the given TokenStream. Read more
Source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
Source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object. Read more

Auto Trait Implementations§

§

impl Freeze for Module

§

impl RefUnwindSafe for Module

§

impl !Send for Module

§

impl !Sync for Module

§

impl Unpin for Module

§

impl UnwindSafe for Module

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<X> AsAny for X
where X: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Get a reference to the current object as Any.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Get a mutable reference to the current object as Any.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T