[][src]Crate proffer

Proffer is a code generation library to create code from other data structures such as JSON or any other reason where generating raw source code is required.

Example

use proffer::*;

let mut ipl = Impl::new("That", None);
ipl.add_generic(Generic::new("T", vec!["ToString"]));

let mut method = Function::new("foo", true);
method.add_parameter(Parameter::new("bar1", "T"));
method.add_parameter(Parameter::new("bar2", "S"));
method.set_return_ty("T");
method.add_generic(Generic::new("S", vec![]));
method.set_body("bar");

ipl.add_function(method);

let expected = r#"
    impl<T> That<T>
        where
            T: ToString,
    {
        pub fn foo<S>(bar1: T, bar2: S) -> T
            where
                S: ,
        {
            bar
        }
    }
"#;

let src_code = ipl.generate();
println!("{}", &src_code);

assert_eq!(
    norm_whitespace(expected),
    norm_whitespace(&src_code)
)

Re-exports

pub use enum_gen::*;
pub use field_gen::*;
pub use function_gen::*;
pub use generics_gen::*;
pub use impl_gen::*;
pub use module_gen::*;
pub use struct_gen::*;
pub use trait_gen::*;
pub use traits::SrcCode;

Modules

enum_gen

Create enum objects

field_gen

Field generation module, represents single fields within a struct

function_gen

Function pieces, specifically Function which is composed of FunctionSignature and FunctionBody. Naturally, a Function can be used as a "method" for another object, by specifying self (or some variant of it) as the first Parameter to a Function object.

generics_gen

Create a single or collection of generics/trait bounds for functions and other objects.

impl_gen

Create impl blocks for functions, traits, and other objects.

module_gen

Create a Module which can hold any number of other SrcCode elements.

struct_gen

Create a struct object.

trait_gen

Create a trait definition

traits

Trait(s) specific to code generation objects within this crate.

Functions

norm_whitespace

Helper function throughout tests and documentation for comparing expected source code generated.