[][src]Trait paperclip::v2::Emitter

pub trait Emitter: Sized {
    type Definition: Schema + Debug;
    fn state(&self) -> &EmitterState;

    fn generate(&self, api: &Api<Self::Definition>) -> Result<(), Error> { ... }
fn def_ns_name<'a>(
        &self,
        def: &'a Self::Definition
    ) -> Result<Box<dyn Iterator<Item = String> + 'a>, Error> { ... }
fn def_name(&self, def: &Self::Definition) -> Result<String, Error> { ... }
fn def_mod_path(&self, def: &Self::Definition) -> Result<PathBuf, Error> { ... }
fn build_def(
        &self,
        def: &Self::Definition,
        define: bool
    ) -> Result<EmittedUnit, Error> { ... } }

Emitter represents the interface for generating the relevant modules, API object definitions and the associated calls.

Associated Types

type Definition: Schema + Debug

The associated Schema implementor.

Loading content...

Required methods

fn state(&self) -> &EmitterState

Returns a reference to the underlying state.

Loading content...

Provided methods

fn generate(&self, api: &Api<Self::Definition>) -> Result<(), Error>

Entrypoint for emitter. Given an API spec, generate code inside Rust modules in the configured working directory.

fn def_ns_name<'a>(
    &self,
    def: &'a Self::Definition
) -> Result<Box<dyn Iterator<Item = String> + 'a>, Error>

Returns an iterator of path components for the given definition.

NOTE: All components are snake_cased (including the definition name).

fn def_name(&self, def: &Self::Definition) -> Result<String, Error>

Returns the CamelCase name for the given definition.

fn def_mod_path(&self, def: &Self::Definition) -> Result<PathBuf, Error>

Returns the module path (from working directory) for the given definition.

NOTE: This doesn't (shouldn't) set any extension to the leaf component.

fn build_def(
    &self,
    def: &Self::Definition,
    define: bool
) -> Result<EmittedUnit, Error>

Builds a given definition. Also takes a bool to specify whether we're planning to define a Rust type or whether we're reusing an existing type.

NOTE: We resolve type aliases to known types.

Loading content...

Implementors

impl<S: Schema + Debug> Emitter for DefaultEmitter<S>[src]

type Definition = S

fn generate(&self, api: &Api<Self::Definition>) -> Result<(), Error>[src]

fn def_ns_name<'a>(
    &self,
    def: &'a Self::Definition
) -> Result<Box<dyn Iterator<Item = String> + 'a>, Error>
[src]

fn def_name(&self, def: &Self::Definition) -> Result<String, Error>[src]

fn def_mod_path(&self, def: &Self::Definition) -> Result<PathBuf, Error>[src]

fn build_def(
    &self,
    def: &Self::Definition,
    define: bool
) -> Result<EmittedUnit, Error>
[src]

Loading content...