fmt::Display implemented for Threads and Posts
parent
172dba215a
commit
7e7c0e2173
@ -1,6 +1,35 @@
|
||||
struct Post {
|
||||
ip: [u8; 4],
|
||||
code: u64,
|
||||
date: String,
|
||||
body: String,
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Post {
|
||||
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