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

#32 in #generate

Download history 1/week @ 2022-03-05 14/week @ 2022-03-12 28/week @ 2022-03-19 1/week @ 2022-04-09 1/week @ 2022-04-16 15/week @ 2022-04-23 36/week @ 2022-04-30 42/week @ 2022-05-07 120/week @ 2022-05-14 26/week @ 2022-05-21 49/week @ 2022-05-28 44/week @ 2022-06-04 1/week @ 2022-06-11 2/week @ 2022-06-18

96 downloads per month

Custom license

46KB
1K SLoC

Proffer

CircleCI crates.io 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

~11MB
~257K SLoC