pub fn export_to_file<T>(
destination: String,
filename: String,
head: Head,
elements: Vec<T>,
) -> Result<()>where
T: Html,Expand description
Exports the elements to an html file.
destination: The destination folder’s path.filename: The html file’s name.head: The html document’s head.elements: The elements to export.
Examples found in repository?
examples/simple_table.rs (lines 61-66)
47fn main() {
48 let persons = vec![
49 Person::new("Johns James".to_string(), 20, "France".to_string()),
50 Person::new("Smith Jennifer".to_string(), 30, "England".to_string()),
51 Person::new("Brown Robert".to_string(), 40, "Australia".to_string()),
52 Person::new("Taylor Mary".to_string(), 50, "South Africa".to_string()),
53 ];
54 let table = from_iterator(
55 &persons,
56 HtmlElementConfig::new_empty(),
57 HtmlElementConfig::new_empty(),
58 )
59 .unwrap();
60 let head = Head::new().with_title("Simple table".to_string());
61 export_to_file(
62 "examples_output".to_string(),
63 "simple_table.html".to_string(),
64 head,
65 vec![table],
66 )
67 .unwrap();
68}More examples
examples/union_table.rs (lines 123-128)
108fn main() {
109 let items = vec![
110 Item::BasicItem(BasicItem::new("Item A".to_string(), 10.0, 3)),
111 Item::BasicItem(BasicItem::new("Item B".to_string(), 11.0, 2)),
112 Item::DiscountedItem(DiscountedItem::new("Item C".to_string(), 20.0, 5, 5.0)),
113 Item::DiscountedItem(DiscountedItem::new("Item D".to_string(), 5.0, 1, 10.0)),
114 Item::BasicItem(BasicItem::new("Item E".to_string(), 100.0, 1)),
115 ];
116 let table = from_iterator(
117 &items,
118 HtmlElementConfig::new_empty(),
119 HtmlElementConfig::new_empty(),
120 )
121 .unwrap();
122 let head = Head::new().with_title("Union table".to_string());
123 export_to_file(
124 "examples_output".to_string(),
125 "union_tables.html".to_string(),
126 head,
127 vec![table],
128 )
129 .unwrap();
130}examples/simple_list.rs (lines 63-68)
46fn main() {
47 let persons = vec![
48 Person::new("Johns James".to_string(), 20, "France".to_string()),
49 Person::new("Smith Jennifer".to_string(), 30, "England".to_string()),
50 Person::new("Brown Robert".to_string(), 40, "Australia".to_string()),
51 Person::new("Taylor Mary".to_string(), 50, "South Africa".to_string()),
52 ];
53 let ul_list = from_iterator(
54 &persons,
55 &ListType::Unordered,
56 HtmlElementConfig::new_empty(),
57 )
58 .unwrap();
59
60 let ol_list =
61 from_iterator(&persons, &ListType::Ordered, HtmlElementConfig::new_empty()).unwrap();
62 let head = Head::new().with_title("Simple list".to_string());
63 export_to_file(
64 "examples_output".to_string(),
65 "simple_list.html".to_string(),
66 head,
67 vec![ul_list, ol_list],
68 )
69 .unwrap();
70}examples/definition_list.rs (lines 88-101)
72fn main() {
73 let mut map = HashMap::new();
74 map.insert(Country("India".to_string()), Population(1_450_935_791));
75 map.insert(Country("China".to_string()), Population(1_419_321_278));
76 map.insert(Country("Usa".to_string()), Population(345_426_571));
77 map.insert(Country("Indonesia".to_string()), Population(283_487_931));
78
79 let languages = vec![
80 ProgrammingLanguage::new("Rust".to_string(), 2006),
81 ProgrammingLanguage::new("C".to_string(), 1972),
82 ProgrammingLanguage::new("Python".to_string(), 1991),
83 ProgrammingLanguage::new("Haskell".to_string(), 1990),
84 ];
85
86 let head = Head::new().with_title("Definition list".to_string());
87
88 export_to_file(
89 "examples_output".to_string(),
90 "definition_list.html".to_string(),
91 head,
92 vec![
93 term_definition_list_from_map(&map, HtmlElementConfig::new_empty()).unwrap(),
94 from_iterator(
95 &languages,
96 &ListType::TermDefinition,
97 HtmlElementConfig::new_empty(),
98 )
99 .unwrap(),
100 ],
101 )
102 .unwrap();
103}examples/forms.rs (lines 447-452)
420fn main() {
421 let car = Car {
422 tyres: Tyres::Winter,
423 benchmark_week: "2025-W18".to_string(),
424 length: 4.5,
425 power: 600.0,
426 hidden_id: "abcdef123".to_string(),
427 brand: CarBrand::Ferrari,
428 model_name: "Ferrari F80".to_string(),
429 last_start_time: "13:45".to_string(),
430 motor: Motor {
431 is_electric: true,
432 is_thermic: true,
433 },
434 color: "#ff0000".to_string(),
435 bought_the: "2018-07-22".to_string(),
436 dealership: DealerShip {
437 website: "https://www.website.com".to_string(),
438 phone: "123-456-7890".to_string(),
439 secret_id: "abc123".to_string(),
440 email: "car@cars.com".to_string(),
441 _bill: String::new(),
442 warranty: "2025-06".to_string(),
443 },
444 description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.".to_string()
445 };
446 let head = Head::new().with_title("Form".to_string());
447 export_to_file(
448 "examples_output".to_string(),
449 "form.html".to_string(),
450 head,
451 vec![car.as_form_field().unwrap()],
452 )
453 .unwrap();
454}