mirror of
https://github.com/LemmyNet/lemmy
synced 2024-10-30 15:21:20 +00:00
Use an associated type instead of Generic.
This commit is contained in:
parent
33c5c21a57
commit
8a25f0f816
@ -5,7 +5,9 @@ pub struct CommunityQuery {
|
||||
community_name: String,
|
||||
}
|
||||
|
||||
impl ToApub<GroupExt> for Community {
|
||||
impl ToApub for Community {
|
||||
type Response = GroupExt;
|
||||
|
||||
// Turn a Lemmy Community into an ActivityPub group that can be sent out over the network.
|
||||
fn to_apub(&self, conn: &PgConnection) -> Result<GroupExt, Error> {
|
||||
let mut group = Group::default();
|
||||
@ -52,7 +54,9 @@ impl ActorType for Community {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromApub<GroupExt> for CommunityForm {
|
||||
impl FromApub for CommunityForm {
|
||||
type ApubType = GroupExt;
|
||||
|
||||
/// Parse an ActivityPub group received from another instance into a Lemmy community.
|
||||
fn from_apub(group: &GroupExt, conn: &PgConnection) -> Result<Self, Error> {
|
||||
let oprops = &group.base.base.object_props;
|
||||
|
@ -126,12 +126,14 @@ fn is_apub_id_valid(apub_id: &Url) -> bool {
|
||||
}
|
||||
|
||||
// TODO Not sure good names for these
|
||||
pub trait ToApub<Response> {
|
||||
fn to_apub(&self, conn: &PgConnection) -> Result<Response, Error>;
|
||||
pub trait ToApub {
|
||||
type Response;
|
||||
fn to_apub(&self, conn: &PgConnection) -> Result<Self::Response, Error>;
|
||||
}
|
||||
|
||||
pub trait FromApub<ApubType> {
|
||||
fn from_apub(apub: &ApubType, conn: &PgConnection) -> Result<Self, Error>
|
||||
pub trait FromApub {
|
||||
type ApubType;
|
||||
fn from_apub(apub: &Self::ApubType, conn: &PgConnection) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
@ -15,7 +15,9 @@ pub async fn get_apub_post(
|
||||
Ok(create_apub_response(&post.to_apub(&db.get().unwrap())?))
|
||||
}
|
||||
|
||||
impl ToApub<Page> for Post {
|
||||
impl ToApub for Post {
|
||||
type Response = Page;
|
||||
|
||||
// Turn a Lemmy post into an ActivityPub page that can be sent out over the network.
|
||||
fn to_apub(&self, conn: &PgConnection) -> Result<Page, Error> {
|
||||
let mut page = Page::default();
|
||||
@ -53,7 +55,9 @@ impl ToApub<Page> for Post {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromApub<Page> for PostForm {
|
||||
impl FromApub for PostForm {
|
||||
type ApubType = Page;
|
||||
|
||||
/// Parse an ActivityPub page received from another instance into a Lemmy post.
|
||||
fn from_apub(page: &Page, conn: &PgConnection) -> Result<PostForm, Error> {
|
||||
let oprops = &page.object_props;
|
||||
|
@ -5,7 +5,9 @@ pub struct UserQuery {
|
||||
user_name: String,
|
||||
}
|
||||
|
||||
impl ToApub<PersonExt> for User_ {
|
||||
impl ToApub for User_ {
|
||||
type Response = PersonExt;
|
||||
|
||||
// Turn a Lemmy Community into an ActivityPub group that can be sent out over the network.
|
||||
fn to_apub(&self, _conn: &PgConnection) -> Result<PersonExt, Error> {
|
||||
// TODO go through all these to_string and to_owned()
|
||||
@ -50,7 +52,8 @@ impl ActorType for User_ {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromApub<PersonExt> for UserForm {
|
||||
impl FromApub for UserForm {
|
||||
type ApubType = PersonExt;
|
||||
/// Parse an ActivityPub person received from another instance into a Lemmy user.
|
||||
fn from_apub(person: &PersonExt, _conn: &PgConnection) -> Result<Self, Error> {
|
||||
let oprops = &person.base.base.object_props;
|
||||
|
Loading…
Reference in New Issue
Block a user