hacker_rs/users.rs
1//! User response models and various metadata about accounts and related objects.
2
3use serde::Deserialize;
4use time::OffsetDateTime;
5
6use crate::HackerNewsID;
7
8/// Represents a Hacker News user and their associated metadata.
9#[derive(Debug, Deserialize)]
10pub struct HackerNewsUser {
11 /// Username of the account.
12 pub id: String,
13 /// Creation date of the item, in Unix Time.
14 #[serde(with = "time::serde::timestamp")]
15 pub created: OffsetDateTime,
16 /// The user's karma.
17 pub karma: u32,
18 /// The user's optional self-description. HTML.
19 pub about: Option<String>,
20 /// List of the user's stories, polls and comments.
21 pub stories: Option<Vec<HackerNewsID>>,
22}
23
24impl HackerNewsUser {
25 /// Determines if the user's about section is populated
26 pub fn has_about_section(&self) -> bool {
27 self.about.is_some()
28 }
29
30 /// Determines if the user has related Hacker News content.
31 pub fn has_related_stories(&self) -> bool {
32 self.stories.is_some()
33 }
34}