/* * This file is part of ActivityStreams Types. * * Copyright © 2018 Riley Trautman * * ActivityStreams Types is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ActivityStreams Types is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ActivityStreams Types. If not, see . */ //! A collection of simple types for extending the ActivityStreams Types base types use serde::{de::DeserializeOwned, ser::Serialize}; use activitystreams_traits::{ Activity, Actor, Collection, CollectionPage, IntransitiveActivity, Link, Object, }; /// A custom type extending Link /// /// CustomLink allows for providing a pre-defined Link type, and a set of extending properties, and /// treating those two items as a single Link type. /// /// ## Example /// ```rust /// use activitystreams_types::{ /// CustomLink, /// link::Mention, /// }; /// /// struct MyProps { /// some_prop: String, /// } /// /// fn main() { /// let mention = Mention::default(); /// let extended_mention = CustomLink::new(mention, MyProps { some_prop: "hey".to_owned() }); /// } /// ``` #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct CustomLink { #[serde(flatten)] pub link: L, #[serde(flatten)] pub custom_props: C, } impl CustomLink { pub fn new(link: L, custom_props: C) -> Self { CustomLink { link, custom_props } } } impl Link for CustomLink where C: DeserializeOwned + Serialize, L: Link, { } /// A custom type extending Object /// /// CustomObject allows for providing a pre-defined Link type, and a set of extending properties, /// and treating those two items as a single Object type. /// /// This type can also be used to extend any type deriving from Object, such as Actor, Activity, or /// Collection. /// /// ## Example /// ```rust /// use activitystreams_types::{ /// CustomObject, /// object::Video, /// }; /// /// struct MyProps { /// some_prop: String, /// } /// /// fn main() { /// let video = Video::default(); /// let extended_video = CustomObject::new(video, MyProps { some_prop: "hey".to_owned() }); /// } /// ``` #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct CustomObject { #[serde(flatten)] pub object: O, #[serde(flatten)] pub custom_props: C, } impl CustomObject { pub fn new(object: O, custom_props: C) -> Self { CustomObject { object, custom_props, } } } impl Object for CustomObject where C: DeserializeOwned + Serialize, O: Object, { } impl Actor for CustomObject where C: DeserializeOwned + Serialize, O: Actor, { } impl Collection for CustomObject where C: DeserializeOwned + Serialize, O: Collection, { } impl CollectionPage for CustomObject where C: DeserializeOwned + Serialize, O: CollectionPage, { } impl Activity for CustomObject where C: DeserializeOwned + Serialize, O: Activity, { } impl IntransitiveActivity for CustomObject where C: DeserializeOwned + Serialize, O: IntransitiveActivity, { }