From fcc2035b467290f4c6c00d984e69903f6a67065e Mon Sep 17 00:00:00 2001 From: "D. Scott Boggs" Date: Mon, 9 Jan 2023 08:26:13 -0500 Subject: [PATCH] Add constructors for ID types --- entities/src/account.rs | 6 ++++++ entities/src/attachment.rs | 6 ++++++ entities/src/filter.rs | 6 ++++++ entities/src/notification.rs | 6 ++++++ entities/src/push.rs | 6 ++++++ entities/src/relationship.rs | 6 ++++++ entities/src/report.rs | 6 ++++++ entities/src/status.rs | 6 ++++++ 8 files changed, 48 insertions(+) diff --git a/entities/src/account.rs b/entities/src/account.rs index f8d0d8c..08ee5cb 100644 --- a/entities/src/account.rs +++ b/entities/src/account.rs @@ -65,6 +65,12 @@ impl AsRef for AccountId { } } +impl AccountId { + pub fn new(value: impl Into) -> Self { + Self(value.into()) + } +} + /// A single name: value pair from a user's profile #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)] pub struct MetadataField { diff --git a/entities/src/attachment.rs b/entities/src/attachment.rs index f34ffb6..b245053 100644 --- a/entities/src/attachment.rs +++ b/entities/src/attachment.rs @@ -35,6 +35,12 @@ impl AsRef for AttachmentId { } } +impl AttachmentId { + pub fn new(value: impl Into) -> Self { + Self(value.into()) + } +} + /// Information about the attachment itself. #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] pub struct Meta { diff --git a/entities/src/filter.rs b/entities/src/filter.rs index dcdcfe1..b6d88e8 100644 --- a/entities/src/filter.rs +++ b/entities/src/filter.rs @@ -62,6 +62,12 @@ impl AsRef for FilterId { } } +impl FilterId { + pub fn new(value: impl Into) -> Self { + Self(value.into()) + } +} + /// Represents the various types of Filter contexts #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] diff --git a/entities/src/notification.rs b/entities/src/notification.rs index df538ff..45f46de 100644 --- a/entities/src/notification.rs +++ b/entities/src/notification.rs @@ -33,6 +33,12 @@ impl AsRef for NotificationId { } } +impl NotificationId { + pub fn new(value: impl Into) -> Self { + Self(value.into()) + } +} + /// The type of notification. #[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)] #[serde(rename_all = "lowercase")] diff --git a/entities/src/push.rs b/entities/src/push.rs index b2a1877..148c40d 100644 --- a/entities/src/push.rs +++ b/entities/src/push.rs @@ -37,6 +37,12 @@ impl AsRef for SubscriptionId { } } +impl SubscriptionId { + pub fn new(value: impl Into) -> Self { + Self(value.into()) + } +} + pub mod add_subscription { use serde::Serialize; diff --git a/entities/src/relationship.rs b/entities/src/relationship.rs index b0357e5..d9ff7c4 100644 --- a/entities/src/relationship.rs +++ b/entities/src/relationship.rs @@ -42,3 +42,9 @@ impl AsRef for RelationshipId { &self.0 } } + +impl RelationshipId { + pub fn new(value: impl Into) -> Self { + Self(value.into()) + } +} diff --git a/entities/src/report.rs b/entities/src/report.rs index 89bbc4c..f94accc 100644 --- a/entities/src/report.rs +++ b/entities/src/report.rs @@ -21,3 +21,9 @@ impl AsRef for ReportId { &self.0 } } + +impl ReportId { + pub fn new(value: impl Into) -> Self { + Self(value.into()) + } +} diff --git a/entities/src/status.rs b/entities/src/status.rs index dd0cf84..89cb1e6 100644 --- a/entities/src/status.rs +++ b/entities/src/status.rs @@ -76,6 +76,12 @@ impl AsRef for StatusId { } } +impl StatusId { + pub fn new(value: impl Into) -> Self { + Self(value.into()) + } +} + /// A mention of another user. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Mention {