]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/newtypes.rs
First pass at invite-only migration. (#1949)
[lemmy.git] / crates / db_schema / src / newtypes.rs
index 3042d35e71bf492f803db2fb1cf52af342e6de61..b863a250014df2d39acfc663612a16b40cbf6cc7 100644 (file)
@@ -4,6 +4,7 @@ use diesel::{
   serialize::{Output, ToSql},
   sql_types::Text,
 };
+use lemmy_apub_lib::{object_id::ObjectId, traits::ApubObject};
 use serde::{Deserialize, Serialize};
 use std::{
   fmt,
@@ -42,7 +43,9 @@ impl fmt::Display for CommentId {
 )]
 pub struct CommunityId(pub i32);
 
-#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
+#[derive(
+  Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType,
+)]
 pub struct LocalUserId(pub i32);
 
 #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
@@ -93,27 +96,32 @@ where
   }
 }
 
-impl DbUrl {
-  // TODO: remove this method and just use into()
-  pub fn into_inner(self) -> Url {
-    self.0
-  }
-}
-
 impl Display for DbUrl {
   fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
     self.to_owned().0.fmt(f)
   }
 }
 
-impl From<DbUrl> for Url {
-  fn from(url: DbUrl) -> Self {
-    url.0
+// the project doesnt compile with From
+#[allow(clippy::from_over_into)]
+impl Into<DbUrl> for Url {
+  fn into(self) -> DbUrl {
+    DbUrl(self)
+  }
+}
+#[allow(clippy::from_over_into)]
+impl Into<Url> for DbUrl {
+  fn into(self) -> Url {
+    self.0
   }
 }
 
-impl From<Url> for DbUrl {
-  fn from(url: Url) -> Self {
-    DbUrl(url)
+impl<Kind> From<ObjectId<Kind>> for DbUrl
+where
+  Kind: ApubObject + Send + 'static,
+  for<'de2> <Kind as ApubObject>::ApubType: serde::Deserialize<'de2>,
+{
+  fn from(id: ObjectId<Kind>) -> Self {
+    DbUrl(id.into())
   }
 }