rtile provides a way to work with rectangular areas of text as atomic units which can be used for code generation
```rust use rtile::*; use std::collections::BTreeMap;
fn codegen() { tp!( structdef, " #[derive(Default, Debug)] @{svis}struct @{sname}{ @{smembers} } " ); let mut input: BTreeMap<&str, (bool, Vec<&str>, Vec<&str>)> = BTreeMap::new(); input.insert( "Person", ( true, vec!["name", "age", "address", "properties"], vec!["String", "u32", "Vec
", "Properties"], ), ); input.insert( "Address", ( true, vec!["street", "city", "state", "zip"], vec!["String", "String", "String", "String"], ), ); input.insert( "Properties", ( true, vec!["gender", "kids", "otherdetails"], vec!["Gender", "Optiontp!(
some_functions,
r#"
fn print_default_person(){
println!("{:#?}",Person::default());
}
"#
);
tp!(
main_function,
r#"
fn main(){
print_default_person();
/*
Person {
name: "",
age: 0,
address: [],
properties: Properties {
gender: Unknown,
kids: None,
other_details: Miscellaneous {
education: None,
employment_status: NotApplicable,
},
},
}
*/
}
"#
);
struct_codes
.into_iter()
.for_each(|code_item| println!("{code_item}\n"));
enum_codes
.into_iter()
.for_each(|code_item| println!("{code_item}\n"));
println!("{impls_default_enums}\n");
println!(
"{}",
t!("
@{some_functions}
@{main_function}
")
);
}
fn main() { codegen(); } ```
```rust
pub struct Address{ pub street: String, pub city: String, pub state: String, pub zip: String, }
pub struct Person{ pub name: String, pub age: u32, pub address: Vec
, pub properties: Properties, }pub struct Properties{
pub gender: Gender,
pub kids: Option
pub enum EmploymentStatus{ Employed, Unemployed, Employer, Retired, NotApplicable, }
pub enum Gender{ Unknown, Male, Female, }
pub enum OtherDetails{
Miscellaneous{education: Option
impl Default for Gender{ fn default()->Self{ Gender::Unknown } } impl Default for EmploymentStatus{ fn default()->Self{ EmploymentStatus::NotApplicable } } impl Default for OtherDetails{ fn default()->Self{ Self::Miscellaneous{ education: None, employment_status: EmploymentStatus::default(), } } }
fn printdefaultperson(){ println!("{:#?}",Person::default()); }
fn main(){ printdefaultperson(); /* Person { name: "", age: 0, address: [], properties: Properties { gender: Unknown, kids: None, otherdetails: Miscellaneous { education: None, employmentstatus: NotApplicable, }, }, } */ } ```