4 serialize::{Output, ToSql},
7 use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject};
8 use serde::{Deserialize, Serialize};
11 fmt::{Display, Formatter},
17 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
19 pub struct PostId(pub i32);
21 impl fmt::Display for PostId {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 write!(f, "{}", self.0)
28 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
30 pub struct PersonId(pub i32);
32 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
33 pub struct CommentId(pub i32);
35 impl fmt::Display for CommentId {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 write!(f, "{}", self.0)
42 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
44 pub struct CommunityId(pub i32);
47 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
49 pub struct LocalUserId(pub i32);
51 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
52 pub struct PrivateMessageId(i32);
54 impl fmt::Display for PrivateMessageId {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 write!(f, "{}", self.0)
60 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
61 pub struct PersonMentionId(i32);
63 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
64 pub struct PersonBlockId(i32);
66 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
67 pub struct CommunityBlockId(i32);
69 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
70 pub struct CommentReportId(i32);
72 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
73 pub struct PostReportId(i32);
76 #[derive(Clone, PartialEq, Serialize, Deserialize, Debug, AsExpression, FromSqlRow)]
78 pub struct DbUrl(Url);
80 impl<DB: Backend> ToSql<Text, DB> for DbUrl
82 String: ToSql<Text, DB>,
84 fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> diesel::serialize::Result {
85 self.0.to_string().to_sql(out)
89 impl<DB: Backend> FromSql<Text, DB> for DbUrl
91 String: FromSql<Text, DB>,
93 fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result<Self> {
94 let str = String::from_sql(bytes)?;
95 Ok(DbUrl(Url::parse(&str)?))
99 impl Display for DbUrl {
100 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
101 self.to_owned().0.fmt(f)
105 // the project doesnt compile with From
106 #[allow(clippy::from_over_into)]
107 impl Into<DbUrl> for Url {
108 fn into(self) -> DbUrl {
112 #[allow(clippy::from_over_into)]
113 impl Into<Url> for DbUrl {
114 fn into(self) -> Url {
119 impl<Kind> From<ObjectId<Kind>> for DbUrl
121 Kind: ApubObject + Send + 'static,
122 for<'de2> <Kind as ApubObject>::ApubType: serde::Deserialize<'de2>,
124 fn from(id: ObjectId<Kind>) -> Self {