From 25323a54aed498f03fca1bd99935db004d4217fd Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Thu, 29 Aug 2019 00:40:28 -0400 Subject: limit number of displayed posts to 30 --- src/main.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 92a8613..65a6022 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,15 +65,23 @@ fn list_matches(db: &db::Conn) { }) .unwrap(); + let mut postvec = Vec::new(); out.for_each(|row| { if let Ok(post) = row { - println!( - "{}. {} -> by {}\n{}", + postvec.push(format!( + "{}. {} -> by {}\n{}\n\n", post.id, post.title, post.author, post.body - ); - println!(); + )); } }); + + for (i, e) in postvec.iter().enumerate() { + if postvec.len() >= 30 && i >= postvec.len() - 31 { + print!("{}", e); + } else if postvec.len() < 30 { + print!("{}", e); + } + } } fn post(db: &db::Conn) { -- cgit 1.4.1-2-gfad0