proffer

Crates.ioproffer
lib.rsproffer
version1.0.0-rc2
sourcesrc
created_at2019-09-29 10:48:56.453334
updated_at2019-11-23 05:28:49.368135
descriptionRust code generation
homepagehttps://github.com/milesgranger/proffer
repositoryhttps://github.com/milesgranger/proffer
max_upload_size
id168596
size67,882
Miles Granger (milesgranger)

documentation

https://docs.rs/crate/proffer/

README

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)
)
Commit count: 54

cargo fmt