4 serialize::{Output, ToSql},
7 use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject};
8 use serde::{Deserialize, Serialize};
11 fmt::{Display, Formatter},
18 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
20 pub struct PostId(pub i32);
22 impl fmt::Display for PostId {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 write!(f, "{}", self.0)
29 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
31 pub struct PersonId(pub i32);
33 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
34 pub struct CommentId(pub i32);
36 impl fmt::Display for CommentId {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 write!(f, "{}", self.0)
43 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
45 pub struct CommunityId(pub i32);
48 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
50 pub struct LocalUserId(pub i32);
52 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
53 pub struct PrivateMessageId(i32);
55 impl fmt::Display for PrivateMessageId {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 write!(f, "{}", self.0)
61 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
62 pub struct PersonMentionId(i32);
64 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
65 pub struct PersonBlockId(i32);
67 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
68 pub struct CommunityBlockId(i32);
70 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
71 pub struct CommentReportId(i32);
73 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
74 pub struct PostReportId(i32);
77 #[derive(Clone, PartialEq, Serialize, Deserialize, Debug, AsExpression, FromSqlRow)]
79 pub struct DbUrl(Url);
81 impl<DB: Backend> ToSql<Text, DB> for DbUrl
83 String: ToSql<Text, DB>,
85 fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> diesel::serialize::Result {
86 self.0.to_string().to_sql(out)
90 impl<DB: Backend> FromSql<Text, DB> for DbUrl
92 String: FromSql<Text, DB>,
94 fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result<Self> {
95 let str = String::from_sql(bytes)?;
96 Ok(DbUrl(Url::parse(&str)?))
100 impl Display for DbUrl {
101 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
102 self.to_owned().0.fmt(f)
106 // the project doesnt compile with From
107 #[allow(clippy::from_over_into)]
108 impl Into<DbUrl> for Url {
109 fn into(self) -> DbUrl {
113 #[allow(clippy::from_over_into)]
114 impl Into<Url> for DbUrl {
115 fn into(self) -> Url {
120 impl<Kind> From<ObjectId<Kind>> for DbUrl
122 Kind: ApubObject + Send + 'static,
123 for<'de2> <Kind as ApubObject>::ApubType: serde::Deserialize<'de2>,
125 fn from(id: ObjectId<Kind>) -> Self {
130 impl Deref for DbUrl {
133 fn deref(&self) -> &Self::Target {