4 serialize::{Output, ToSql},
7 use serde::{Deserialize, Serialize};
10 fmt::{Display, Formatter},
16 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
18 pub struct PostId(pub i32);
20 impl fmt::Display for PostId {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 write!(f, "{}", self.0)
27 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
29 pub struct PersonId(pub i32);
31 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
32 pub struct CommentId(pub i32);
34 impl fmt::Display for CommentId {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 write!(f, "{}", self.0)
41 Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
43 pub struct CommunityId(pub i32);
45 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
46 pub struct LocalUserId(pub i32);
48 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
49 pub struct PrivateMessageId(i32);
51 impl fmt::Display for PrivateMessageId {
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 write!(f, "{}", self.0)
57 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
58 pub struct PersonMentionId(i32);
60 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
61 pub struct PersonBlockId(i32);
63 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
64 pub struct CommunityBlockId(i32);
66 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
67 pub struct CommentReportId(i32);
69 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
70 pub struct PostReportId(i32);
73 #[derive(Clone, PartialEq, Serialize, Deserialize, Debug, AsExpression, FromSqlRow)]
75 pub struct DbUrl(Url);
77 impl<DB: Backend> ToSql<Text, DB> for DbUrl
79 String: ToSql<Text, DB>,
81 fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> diesel::serialize::Result {
82 self.0.to_string().to_sql(out)
86 impl<DB: Backend> FromSql<Text, DB> for DbUrl
88 String: FromSql<Text, DB>,
90 fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result<Self> {
91 let str = String::from_sql(bytes)?;
92 Ok(DbUrl(Url::parse(&str)?))
97 // TODO: remove this method and just use into()
98 pub fn into_inner(self) -> Url {
103 impl Display for DbUrl {
104 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
105 self.to_owned().0.fmt(f)
109 impl From<DbUrl> for Url {
110 fn from(url: DbUrl) -> Self {
115 impl From<Url> for DbUrl {
116 fn from(url: Url) -> Self {