1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#![warn(missing_docs)] //! //! 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) //! ) //! ``` //! //! mod internal; pub mod gen; pub use gen::*; pub mod traits; pub use traits::*; /// Helper function throughout tests and documentation /// for comparing expected source code generated. #[must_use] pub fn norm_whitespace(s: &str) -> String { s.split('\n') .map(str::trim) .filter(|l| !l.is_empty()) .collect::<Vec<&str>>() .join("\n") }