fmt::Display implemented for Threads and Posts
parent
172dba215a
commit
7e7c0e2173
@ -1,6 +1,35 @@
|
|||||||
struct Post {
|
use std::fmt;
|
||||||
ip: [u8; 4],
|
|
||||||
code: u64,
|
#[derive(Debug, Clone)]
|
||||||
date: String,
|
pub struct Post {
|
||||||
body: String,
|
pub id: u64,
|
||||||
|
pub ip: [u8; 4],
|
||||||
|
pub date: String,
|
||||||
|
pub body: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Post {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"<article><div><span class=\"info\">{} {}</span></div><p>{}</p></article>",
|
||||||
|
self.id, self.date, self.body,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Thread {
|
||||||
|
pub id: u64,
|
||||||
|
pub topic: String,
|
||||||
|
pub posts: Vec<Post>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Thread {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let posts: String = self
|
||||||
|
.posts
|
||||||
|
.iter()
|
||||||
|
.fold(String::from(""), |a, b| format!("{}{}", a, b));
|
||||||
|
write!(f, "{}", posts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue