7 releases (4 breaking)

1.0.0-rc2 Nov 23, 2019
1.0.0-rc1 Nov 9, 2019
0.5.0 Oct 27, 2019
0.4.0 Oct 7, 2019
0.1.0 Sep 29, 2019

#435 in Build Utils

Custom license

47KB
1K SLoC

Proffer

CircleCI License Coverage Status

API Documentation

Code generation for Rust

Namely useful for generating source code from other data such as JSON

Example

See the documentation for more examples

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("bar")
            .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: ,
        {
            bar
        }
    }
"#;

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

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

Dependencies

~10–18MB
~262K SLoC