refactor: address review — sort_by_key and optional comment timestamps
This commit is contained in:
@@ -42,7 +42,7 @@ struct Statistics {
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct RawComment {
|
||||
comment: String,
|
||||
timestamp: u64,
|
||||
timestamp: Option<u64>,
|
||||
}
|
||||
|
||||
pub fn request_urls(number: &str) -> Vec<String> {
|
||||
@@ -96,13 +96,13 @@ pub fn parse(body: &str) -> Result<ParsedEntry, ParseError> {
|
||||
.into_iter()
|
||||
.filter(|raw| !raw.comment.trim().is_empty())
|
||||
.map(|raw| ParsedComment {
|
||||
timestamp: Some((raw.timestamp / 1000) as i64),
|
||||
timestamp: raw.timestamp.map(|millis| (millis / 1000) as i64),
|
||||
title: None,
|
||||
message: raw.comment,
|
||||
})
|
||||
.collect();
|
||||
|
||||
comments.sort_by(|a, b| b.timestamp.cmp(&a.timestamp));
|
||||
comments.sort_by_key(|comment| std::cmp::Reverse(comment.timestamp));
|
||||
|
||||
return Ok(ParsedEntry {
|
||||
messages: Vec::new(),
|
||||
|
||||
Reference in New Issue
Block a user