1 #[cfg(feature = "full")]
2 use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject};
3 #[cfg(feature = "full")]
4 use diesel_ltree::Ltree;
5 use serde::{Deserialize, Serialize};
8 fmt::{Display, Formatter},
13 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
14 #[cfg_attr(feature = "full", derive(DieselNewType))]
15 pub struct PostId(pub i32);
17 impl fmt::Display for PostId {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 write!(f, "{}", self.0)
23 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
24 #[cfg_attr(feature = "full", derive(DieselNewType))]
25 pub struct PersonId(pub i32);
27 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
28 #[cfg_attr(feature = "full", derive(DieselNewType))]
29 pub struct CommentId(pub i32);
31 impl fmt::Display for CommentId {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 write!(f, "{}", self.0)
37 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
38 #[cfg_attr(feature = "full", derive(DieselNewType))]
39 pub struct CommunityId(pub i32);
41 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize)]
42 #[cfg_attr(feature = "full", derive(DieselNewType))]
43 pub struct LocalUserId(pub i32);
45 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
46 #[cfg_attr(feature = "full", derive(DieselNewType))]
47 pub struct PrivateMessageId(i32);
49 impl fmt::Display for PrivateMessageId {
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 write!(f, "{}", self.0)
55 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
56 #[cfg_attr(feature = "full", derive(DieselNewType))]
57 pub struct PersonMentionId(i32);
59 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
60 #[cfg_attr(feature = "full", derive(DieselNewType))]
61 pub struct PersonBlockId(i32);
63 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
64 #[cfg_attr(feature = "full", derive(DieselNewType))]
65 pub struct CommunityBlockId(i32);
67 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
68 #[cfg_attr(feature = "full", derive(DieselNewType))]
69 pub struct CommentReportId(i32);
71 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
72 #[cfg_attr(feature = "full", derive(DieselNewType))]
73 pub struct PostReportId(i32);
75 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
76 #[cfg_attr(feature = "full", derive(DieselNewType))]
77 pub struct PrivateMessageReportId(i32);
79 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
80 #[cfg_attr(feature = "full", derive(DieselNewType))]
81 pub struct SiteId(i32);
83 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
84 #[cfg_attr(feature = "full", derive(DieselNewType))]
85 pub struct LanguageId(pub i32);
87 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
88 #[cfg_attr(feature = "full", derive(DieselNewType))]
89 pub struct LocalUserLanguageId(pub i32);
91 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
92 #[cfg_attr(feature = "full", derive(DieselNewType))]
93 pub struct SiteLanguageId(pub i32);
95 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
96 #[cfg_attr(feature = "full", derive(DieselNewType))]
97 pub struct CommunityLanguageId(pub i32);
99 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
100 #[cfg_attr(feature = "full", derive(DieselNewType))]
101 pub struct CommentReplyId(i32);
103 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
104 #[cfg_attr(feature = "full", derive(DieselNewType))]
105 pub struct InstanceId(i32);
107 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
108 #[cfg_attr(feature = "full", derive(DieselNewType))]
109 pub struct LocalSiteId(i32);
112 #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
113 #[cfg_attr(feature = "full", derive(AsExpression, FromSqlRow))]
114 #[cfg_attr(feature = "full", diesel(sql_type = diesel::sql_types::Text))]
115 pub struct DbUrl(pub(crate) Box<Url>);
117 #[cfg(feature = "full")]
118 #[derive(Serialize, Deserialize)]
119 #[serde(remote = "Ltree")]
120 /// Do remote derivation for the Ltree struct
121 pub struct LtreeDef(pub String);
123 impl Display for DbUrl {
124 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
125 self.clone().0.fmt(f)
129 // the project doesnt compile with From
130 #[allow(clippy::from_over_into)]
131 impl Into<DbUrl> for Url {
132 fn into(self) -> DbUrl {
133 DbUrl(Box::new(self))
136 #[allow(clippy::from_over_into)]
137 impl Into<Url> for DbUrl {
138 fn into(self) -> Url {
142 #[cfg(feature = "full")]
143 impl<T> From<DbUrl> for ObjectId<T>
145 T: ApubObject + Send,
146 for<'de2> <T as ApubObject>::ApubType: Deserialize<'de2>,
148 fn from(value: DbUrl) -> Self {
153 impl Deref for DbUrl {
156 fn deref(&self) -> &Self::Target {