Expand description
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 ipl = Impl::new("That")
.add_generic(Generic::new("T").add_trait_bounds(vec!["ToString"]).to_owned())
.add_function(
Function::new("foo")
.set_is_pub(true)
.add_parameter(Parameter::new("bar1", "T"))
.add_parameter(Parameter::new("bar2", "S"))
.set_return_ty("T")
.add_generic(Generic::new("S"))
.set_body("bar1")
.to_owned()
).to_owned();
let expected = r#"
impl<T> That<T>
where
T: ToString,
{
pub fn foo<S>(bar1: T, bar2: S) -> T
where
S: ,
{
bar1
}
}
"#;
let src_code = ipl.generate();
println!("{}", &src_code);
assert_eq!(
norm_whitespace(expected),
norm_whitespace(&src_code)
)Re-exports§
pub use traits::SrcCode;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 associated_types_gen::*;
Modules§
- associated_
types_ gen - Create a associated type for traits and trait implementations.
- enum_
gen - Create
enumobjects - field_
gen Fieldgeneration module, represents single fields within astruct- function_
gen - Function pieces, specifically
Functionwhich is composed ofFunctionSignatureandFunctionBody. Naturally, aFunctioncan be used as a “method” for another object, by specifyingself(or some variant of it) as the firstParameterto aFunctionobject. - generics_
gen - Create a single or collection of generics/trait bounds for functions and other objects.
- impl_
gen - Create
implblocks for functions, traits, and other objects. - module_
gen - Create a
Modulewhich can hold any number of otherSrcCodeelements. - struct_
gen - Create a
structobject. - trait_
gen - Create a
traitdefinition - 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.