Skip to content

Commit

Permalink
fixup: make optional JSON fields nullable
Browse files Browse the repository at this point in the history
Makes optional JSON fields nullable by changing them to `Option<T>`
types.
  • Loading branch information
threadiverse committed Dec 23, 2023
1 parent 27b9749 commit e88c6ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/counts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tui::widgets::ListState;
/// [Comment](crate::comment::Comment), etc.
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct Counts {
pub id: u64,
pub id: Option<u64>,
pub post_id: Option<u64>,
pub comment_id: Option<u64>,
pub comments: Option<u64>,
Expand All @@ -27,7 +27,7 @@ impl Counts {
/// Creates a new [Counts].
pub const fn new() -> Counts {
Self {
id: 0,
id: None,
post_id: None,
comment_id: None,
comments: None,
Expand All @@ -46,8 +46,8 @@ impl Counts {
}

/// Gets the [Counts] ID.
pub const fn id(&self) -> u64 {
self.id
pub fn id(&self) -> u64 {
self.id.clone().unwrap_or(0)
}

/// Gets whether the [Counts] are for a [Post](crate::posts::Post).
Expand Down
4 changes: 2 additions & 2 deletions src/posts/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Creator {
pub local: bool,
pub icon: Option<String>,
pub deleted: bool,
pub admin: bool,
pub admin: Option<bool>,
pub bot_account: bool,
pub instance_id: u64,
}
Expand All @@ -30,7 +30,7 @@ impl Creator {
local: false,
icon: None,
deleted: false,
admin: false,
admin: None,
bot_account: false,
instance_id: 0,
}
Expand Down

0 comments on commit e88c6ab

Please sign in to comment.