Implement std::format::Display for all Id types

This commit is contained in:
D. Scott Boggs 2023-01-21 11:04:19 -05:00 committed by Scott Boggs
parent eeac76c750
commit be39ca6e24
9 changed files with 70 additions and 1 deletions

View File

@ -4,7 +4,7 @@ use serde::{
de::{self, Deserializer, Unexpected},
Deserialize, Serialize,
};
use std::path::PathBuf;
use std::{fmt::Display, path::PathBuf};
use time::{serde::iso8601, OffsetDateTime};
/// A struct representing an Account.
@ -71,6 +71,12 @@ impl AccountId {
}
}
impl Display for AccountId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
static_assertions::assert_not_impl_any!(
AccountId: PartialEq<crate::attachment::AttachmentId>,
PartialEq<crate::filter::FilterId>,

View File

@ -1,5 +1,7 @@
//! Module containing everything related to media attachements.
use std::fmt::Display;
use serde::{Deserialize, Serialize};
/// A struct representing a media attachment.
@ -41,6 +43,12 @@ impl AttachmentId {
}
}
impl Display for AttachmentId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
static_assertions::assert_not_impl_any!(
AttachmentId: PartialEq<crate::account::AccountId>,
PartialEq<crate::filter::FilterId>,

View File

@ -1,3 +1,5 @@
use std::fmt::Display;
use serde::{de::Visitor, Deserialize, Deserializer, Serialize};
use time::{serde::iso8601, OffsetDateTime};
@ -68,6 +70,12 @@ impl FilterId {
}
}
impl Display for FilterId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
static_assertions::assert_not_impl_any!(
FilterId: PartialEq<crate::account::AccountId>,
PartialEq<crate::attachment::AttachmentId>,

View File

@ -1,3 +1,5 @@
use std::fmt::Display;
use serde::{Deserialize, Serialize};
/// Represents a `mention` used in a status
@ -30,6 +32,12 @@ impl MentionId {
}
}
impl Display for MentionId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
static_assertions::assert_not_impl_any!(
Mention: PartialEq<crate::account::AccountId>,
PartialEq<crate::attachment::AttachmentId>,

View File

@ -1,5 +1,7 @@
//! Module containing all info about notifications.
use std::fmt::Display;
use super::{account::Account, status::Status};
use serde::{Deserialize, Serialize};
use time::{serde::iso8601, OffsetDateTime};
@ -39,6 +41,12 @@ impl NotificationId {
}
}
impl Display for NotificationId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
static_assertions::assert_not_impl_any!(
NotificationId: PartialEq<crate::account::AccountId>,
PartialEq<crate::attachment::AttachmentId>,

View File

@ -1,3 +1,5 @@
use std::fmt::Display;
use serde::{Deserialize, Serialize};
/// Represents the `alerts` key of the `Subscription` object
@ -43,6 +45,12 @@ impl SubscriptionId {
}
}
impl Display for SubscriptionId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
static_assertions::assert_not_impl_any!(
SubscriptionId: PartialEq<crate::account::AccountId>,
PartialEq<crate::attachment::AttachmentId>,

View File

@ -1,6 +1,8 @@
//! module containing everything relating to a relationship with
//! another account.
use std::fmt::Display;
use serde::{Deserialize, Serialize};
/// A struct containing information about a relationship with another account.
@ -48,6 +50,11 @@ impl RelationshipId {
Self(value.into())
}
}
impl Display for RelationshipId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
static_assertions::assert_not_impl_any!(
RelationshipId: PartialEq<crate::account::AccountId>,

View File

@ -1,5 +1,7 @@
//! module containing information about a finished report of a user.
use std::fmt::Display;
use serde::{Deserialize, Serialize};
/// A struct containing info about a report.
@ -28,6 +30,12 @@ impl ReportId {
}
}
impl Display for ReportId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
static_assertions::assert_not_impl_any!(
ReportId: PartialEq<crate::account::AccountId>,
PartialEq<crate::attachment::AttachmentId>,

View File

@ -1,5 +1,7 @@
//! Module containing all info relating to a status.
use std::fmt::Display;
use super::prelude::*;
use crate::{card::Card, visibility::Visibility};
use serde::{Deserialize, Serialize};
@ -82,6 +84,12 @@ impl StatusId {
}
}
impl Display for StatusId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
static_assertions::assert_not_impl_any!(
StatusId: PartialEq<crate::account::AccountId>,
PartialEq<crate::attachment::AttachmentId>,