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);
111 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Default)]
112 #[cfg_attr(feature = "full", derive(DieselNewType))]
113 pub struct CustomEmojiId(i32);
116 #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
117 #[cfg_attr(feature = "full", derive(AsExpression, FromSqlRow))]
118 #[cfg_attr(feature = "full", diesel(sql_type = diesel::sql_types::Text))]
119 pub struct DbUrl(pub(crate) Box<Url>);
121 #[cfg(feature = "full")]
122 #[derive(Serialize, Deserialize)]
123 #[serde(remote = "Ltree")]
124 /// Do remote derivation for the Ltree struct
125 pub struct LtreeDef(pub String);
127 impl Display for DbUrl {
128 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
129 self.clone().0.fmt(f)
133 // the project doesnt compile with From
134 #[allow(clippy::from_over_into)]
135 impl Into<DbUrl> for Url {
136 fn into(self) -> DbUrl {
137 DbUrl(Box::new(self))
140 #[allow(clippy::from_over_into)]
141 impl Into<Url> for DbUrl {
142 fn into(self) -> Url {
146 #[cfg(feature = "full")]
147 impl<T> From<DbUrl> for ObjectId<T>
149 T: ApubObject + Send,
150 for<'de2> <T as ApubObject>::ApubType: Deserialize<'de2>,
152 fn from(value: DbUrl) -> Self {
157 impl Deref for DbUrl {
160 fn deref(&self) -> &Self::Target {