Skip to content

Commit 7b506f9

Browse files
committed
feat: allow creating body from a vector of ToString
Signed-off-by: azjezz <azjezz@protonmail.com>
1 parent 06b1027 commit 7b506f9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/body.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ impl Generator for Body {
7575
}
7676
}
7777

78+
impl<T: ToString> From<Vec<T>> for Body {
79+
fn from(body: Vec<T>) -> Self {
80+
let body = body
81+
.iter()
82+
.map(|line| line.to_string())
83+
.collect::<Vec<String>>();
84+
85+
Self {
86+
factory: Some(Box::new(move |indentation, level| {
87+
let body = body.clone();
88+
89+
body.iter()
90+
.map(|line| indentation.indent(&line.to_string(), level))
91+
.collect::<Vec<String>>()
92+
.join("\n")
93+
})),
94+
semicolon_for_empty: true,
95+
}
96+
}
97+
}
98+
7899
impl From<String> for Body {
79100
fn from(body: String) -> Self {
80101
Self {

0 commit comments

Comments
 (0)