diff --git a/src/activitypub/mod.rs b/src/activitypub/mod.rs index 0233549a..60b2a93f 100644 --- a/src/activitypub/mod.rs +++ b/src/activitypub/mod.rs @@ -17,16 +17,15 @@ pub struct Page { } pub async fn view(State(ctx): State) -> Result, StatusCode> { - let mut base = activitystream::object(); - base - .set_actor_type(Some(ActorType::Application)) - .set_id(Some(&url!(ctx, ""))) - .set_name(Some("μpub")) - .set_summary(Some("micro social network, federated")) - .set_inbox(Node::link(&url!(ctx, "/inbox"))) - .set_outbox(Node::link(&url!(ctx, "/outbox"))); - - Ok(Json(base)) + Ok(Json( + activitystream::object() + .set_actor_type(Some(ActorType::Application)) + .set_id(Some(&url!(ctx, ""))) + .set_name(Some("μpub")) + .set_summary(Some("micro social network, federated")) + .set_inbox(Node::link(url!(ctx, "/inbox"))) + .set_outbox(Node::link(url!(ctx, "/outbox"))) + )) } pub async fn inbox(State(ctx) : State, Json(object): Json) -> Result, StatusCode> { diff --git a/src/activitypub/user.rs b/src/activitypub/user.rs index e582cb54..f18f71df 100644 --- a/src/activitypub/user.rs +++ b/src/activitypub/user.rs @@ -54,24 +54,24 @@ pub async fn outbox( .into_iter() .map(|i| i.underlying_json_object()) .collect(); - let mut obj = activitystream::object(); - obj - // TODO set id, calculate uri from given args - .set_collection_type(Some(CollectionType::OrderedCollectionPage)) - .set_part_of(Node::link(&url!(ctx, "/users/{id}/outbox"))) - .set_next(Node::link(&url!(ctx, "/users/{id}/outbox?page=true&max_id={next}"))) - .set_ordered_items(Node::array(items)); - Ok(Json(obj)) + Ok(Json( + activitystream::object() + // TODO set id, calculate uri from given args + .set_collection_type(Some(CollectionType::OrderedCollectionPage)) + .set_part_of(Node::link(url!(ctx, "/users/{id}/outbox"))) + .set_next(Node::link(url!(ctx, "/users/{id}/outbox?page=true&max_id={next}"))) + .set_ordered_items(Node::array(items)) + )) }, } } else { - let mut obj = crate::activitystream::object(); - obj - .set_id(Some(&url!(ctx, "/users/{id}/outbox"))) - .set_collection_type(Some(CollectionType::OrderedCollection)) - .set_first(Node::link(&url!(ctx, "/users/{id}/outbox?page=true"))); - Ok(Json(obj.underlying_json_object())) + Ok(Json( + crate::activitystream::object() + .set_id(Some(&url!(ctx, "/users/{id}/outbox"))) + .set_collection_type(Some(CollectionType::OrderedCollection)) + .set_first(Node::link(url!(ctx, "/users/{id}/outbox?page=true"))) + )) } } diff --git a/src/activitystream/link.rs b/src/activitystream/link.rs index 1dbf4204..19bd284f 100644 --- a/src/activitystream/link.rs +++ b/src/activitystream/link.rs @@ -1,4 +1,4 @@ -use crate::strenum; +use crate::{getter, setter, strenum}; strenum! { pub enum LinkType { @@ -10,23 +10,23 @@ strenum! { pub trait Link : super::Base { fn href(&self) -> &str; fn rel(&self) -> Option<&str> { None } - fn media_type(&self) -> Option<&str> { None } // also in obj - fn name(&self) -> Option<&str> { None } // also in obj + fn link_media_type(&self) -> Option<&str> { None } // also in obj + fn link_name(&self) -> Option<&str> { None } // also in obj fn hreflang(&self) -> Option<&str> { None } - fn height(&self) -> Option<&str> { None } - fn width(&self) -> Option<&str> { None } - fn preview(&self) -> Option<&str> { None } // also in obj + fn height(&self) -> Option { None } + fn width(&self) -> Option { None } + fn link_preview(&self) -> Option<&str> { None } // also in obj } pub trait LinkMut : super::BaseMut { - fn set_href(&mut self, href: &str) -> &mut Self; - fn set_rel(&mut self, val: Option<&str>) -> &mut Self; - fn set_media_type(&mut self, val: Option<&str>) -> &mut Self; // also in obj - fn set_name(&mut self, val: Option<&str>) -> &mut Self; // also in obj - fn set_hreflang(&mut self, val: Option<&str>) -> &mut Self; - fn set_height(&mut self, val: Option<&str>) -> &mut Self; - fn set_width(&mut self, val: Option<&str>) -> &mut Self; - fn set_preview(&mut self, val: Option<&str>) -> &mut Self; // also in obj + fn set_href(self, href: &str) -> Self; + fn set_rel(self, val: Option<&str>) -> Self; + fn set_link_media_type(self, val: Option<&str>) -> Self; // also in obj + fn set_link_name(self, val: Option<&str>) -> Self; // also in obj + fn set_hreflang(self, val: Option<&str>) -> Self; + fn set_height(self, val: Option) -> Self; + fn set_width(self, val: Option) -> Self; + fn set_link_preview(self, val: Option<&str>) -> Self; // also in obj } impl Link for String { @@ -36,19 +36,51 @@ impl Link for String { } impl Link for serde_json::Value { - // TODO this is unchecked and can panic + // TODO this can fail, but it should never do! fn href(&self) -> &str { match self { serde_json::Value::String(x) => x, serde_json::Value::Object(map) => map.get("href") - .unwrap() - .as_str() - .unwrap(), - _ => panic!("invalid value for Link"), - + .map(|h| h.as_str().unwrap_or("")) + .unwrap_or(""), + _ => { + tracing::error!("failed getting href on invalid json Link object"); + "" + }, } } - // ... TODO! + getter! { rel -> &str } + getter! { link_media_type::mediaType -> &str } + getter! { link_name::name -> &str } + getter! { hreflang -> &str } + getter! { height -> u64 } + getter! { width -> u64 } + getter! { link_preview::preview -> &str } +} + +impl LinkMut for serde_json::Value { + // TODO this can fail, but it should never do! + fn set_href(mut self, href: &str) -> Self { + match &mut self { + serde_json::Value::String(x) => *x = href.to_string(), + serde_json::Value::Object(map) => { + map.insert( + "href".to_string(), + serde_json::Value::String(href.to_string()) + ); + }, + _ => tracing::error!("failed setting href on invalid json Link object"), + } + self + } + + setter! { rel -> &str } + setter! { link_media_type::mediaType -> &str } + setter! { link_name::name -> &str } + setter! { hreflang -> &str } + setter! { height -> u64 } + setter! { width -> u64 } + setter! { link_preview::preview -> &str } } diff --git a/src/activitystream/macros.rs b/src/activitystream/macros.rs index 8b22becf..7366019d 100644 --- a/src/activitystream/macros.rs +++ b/src/activitystream/macros.rs @@ -187,9 +187,9 @@ macro_rules! getter { macro_rules! setter { ($name:ident -> &str) => { paste::item! { - fn [< set_$name >](&mut self, val: Option<&str>) -> &mut Self { + fn [< set_$name >](mut self, val: Option<&str>) -> Self { $crate::activitystream::macros::set_maybe_value( - self, stringify!($name), val.map(|x| serde_json::Value::String(x.to_string())) + &mut self, stringify!($name), val.map(|x| serde_json::Value::String(x.to_string())) ); self } @@ -198,9 +198,9 @@ macro_rules! setter { ($name:ident::$rename:ident -> &str) => { paste::item! { - fn [< set_$name >](&mut self, val: Option<&str>) -> &mut Self { + fn [< set_$name >](mut self, val: Option<&str>) -> Self { $crate::activitystream::macros::set_maybe_value( - self, stringify!($rename), val.map(|x| serde_json::Value::String(x.to_string())) + &mut self, stringify!($rename), val.map(|x| serde_json::Value::String(x.to_string())) ); self } @@ -209,9 +209,9 @@ macro_rules! setter { ($name:ident -> u64) => { paste::item! { - fn [< set_$name >](&mut self, val: Option) -> &mut Self { + fn [< set_$name >](mut self, val: Option) -> Self { $crate::activitystream::macros::set_maybe_value( - self, stringify!($name), val.map(|x| serde_json::Value::Number(serde_json::Number::from(x))) + &mut self, stringify!($name), val.map(|x| serde_json::Value::Number(serde_json::Number::from(x))) ); self } @@ -220,9 +220,9 @@ macro_rules! setter { ($name:ident::$rename:ident -> u64) => { paste::item! { - fn [< set_$name >](&mut self, val: Option) -> &mut Self { + fn [< set_$name >](mut self, val: Option) -> Self { $crate::activitystream::macros::set_maybe_value( - self, stringify!($rename), val.map(|x| serde_json::Value::Number(serde_json::Number::from(x))) + &mut self, stringify!($rename), val.map(|x| serde_json::Value::Number(serde_json::Number::from(x))) ); self } @@ -231,9 +231,9 @@ macro_rules! setter { ($name:ident -> chrono::DateTime) => { paste::item! { - fn [< set_$name >](&mut self, val: Option>) -> &mut Self { + fn [< set_$name >](mut self, val: Option>) -> Self { $crate::activitystream::macros::set_maybe_value( - self, stringify!($name), val.map(|x| serde_json::Value::String(x.to_rfc3339())) + &mut self, stringify!($name), val.map(|x| serde_json::Value::String(x.to_rfc3339())) ); self } @@ -242,9 +242,9 @@ macro_rules! setter { ($name:ident::$rename:ident -> chrono::DateTime) => { paste::item! { - fn [< set_$name >](&mut self, val: Option>) -> &mut Self { + fn [< set_$name >](mut self, val: Option>) -> Self { $crate::activitystream::macros::set_maybe_value( - self, stringify!($rename), val.map(|x| serde_json::Value::String(x.to_rfc3339())) + &mut self, stringify!($rename), val.map(|x| serde_json::Value::String(x.to_rfc3339())) ); self } @@ -253,9 +253,9 @@ macro_rules! setter { ($name:ident -> node $t:ty ) => { paste::item! { - fn [< set_$name >](&mut self, val: $crate::activitystream::Node<$t>) -> &mut Self { + fn [< set_$name >](mut self, val: $crate::activitystream::Node<$t>) -> Self { $crate::activitystream::macros::set_maybe_node( - self, stringify!($name), val + &mut self, stringify!($name), val ); self } @@ -264,9 +264,9 @@ macro_rules! setter { ($name:ident::$rename:ident -> node $t:ty ) => { paste::item! { - fn [< set_$name >](&mut self, val: $crate::activitystream::Node<$t>) -> &mut Self { + fn [< set_$name >](mut self, val: $crate::activitystream::Node<$t>) -> Self { $crate::activitystream::macros::set_maybe_node( - self, stringify!($rename), val + &mut self, stringify!($rename), val ); self } @@ -275,9 +275,9 @@ macro_rules! setter { ($name:ident -> type $t:ty ) => { paste::item! { - fn [< set_$name >](&mut self, val: Option<$t>) -> &mut Self { + fn [< set_$name >](mut self, val: Option<$t>) -> Self { $crate::activitystream::macros::set_maybe_value( - self, "type", val.map(|x| serde_json::Value::String(x.as_ref().to_string())) + &mut self, "type", val.map(|x| serde_json::Value::String(x.as_ref().to_string())) ); self } diff --git a/src/activitystream/mod.rs b/src/activitystream/mod.rs index ad0c7043..9ef5c087 100644 --- a/src/activitystream/mod.rs +++ b/src/activitystream/mod.rs @@ -8,6 +8,7 @@ pub mod node; pub use node::Node; pub mod macros; +pub mod prelude; use crate::{getter, setter, strenum}; @@ -41,8 +42,8 @@ pub fn object() -> serde_json::Value { } pub trait BaseMut { - fn set_id(&mut self, val: Option<&str>) -> &mut Self; - fn set_base_type(&mut self, val: Option) -> &mut Self; + fn set_id(self, val: Option<&str>) -> Self; + fn set_base_type(self, val: Option) -> Self; } diff --git a/src/activitystream/object/activity/accept.rs b/src/activitystream/object/activity/accept.rs index ce394905..93c35aa3 100644 --- a/src/activitystream/object/activity/accept.rs +++ b/src/activitystream/object/activity/accept.rs @@ -12,5 +12,5 @@ pub trait Accept : super::Activity { } pub trait AcceptMut : super::ActivityMut { - fn set_accept_type(&mut self, val: Option) -> &mut Self; + fn set_accept_type(self, val: Option) -> Self; } diff --git a/src/activitystream/object/activity/ignore.rs b/src/activitystream/object/activity/ignore.rs index efd52ee7..f3688bbc 100644 --- a/src/activitystream/object/activity/ignore.rs +++ b/src/activitystream/object/activity/ignore.rs @@ -12,5 +12,5 @@ pub trait Ignore : super::Activity { } pub trait IgnoreMut : super::ActivityMut { - fn set_ignore_type(&mut self, val: Option) -> &mut Self; + fn set_ignore_type(self, val: Option) -> Self; } diff --git a/src/activitystream/object/activity/intransitive.rs b/src/activitystream/object/activity/intransitive.rs index 299ea335..d742cbf4 100644 --- a/src/activitystream/object/activity/intransitive.rs +++ b/src/activitystream/object/activity/intransitive.rs @@ -14,5 +14,5 @@ pub trait IntransitiveActivity : super::Activity { } pub trait IntransitiveActivityMut : super::ActivityMut { - fn set_intransitive_activity_type(&mut self, val: Option) -> &mut Self; + fn set_intransitive_activity_type(self, val: Option) -> Self; } diff --git a/src/activitystream/object/activity/mod.rs b/src/activitystream/object/activity/mod.rs index 24000996..13cee8c7 100644 --- a/src/activitystream/object/activity/mod.rs +++ b/src/activitystream/object/activity/mod.rs @@ -52,13 +52,13 @@ pub trait Activity : super::Object { } pub trait ActivityMut : super::ObjectMut { - fn set_activity_type(&mut self, val: Option) -> &mut Self; - fn set_actor(&mut self, val: Node) -> &mut Self; - fn set_object(&mut self, val: Node) -> &mut Self; - fn set_target(&mut self, val: Node) -> &mut Self; - fn set_result(&mut self, val: Node) -> &mut Self; - fn set_origin(&mut self, val: Node) -> &mut Self; - fn set_instrument(&mut self, val: Node) -> &mut Self; + fn set_activity_type(self, val: Option) -> Self; + fn set_actor(self, val: Node) -> Self; + fn set_object(self, val: Node) -> Self; + fn set_target(self, val: Node) -> Self; + fn set_result(self, val: Node) -> Self; + fn set_origin(self, val: Node) -> Self; + fn set_instrument(self, val: Node) -> Self; } impl Activity for serde_json::Value { diff --git a/src/activitystream/object/activity/offer.rs b/src/activitystream/object/activity/offer.rs index a9d36184..92cf8b63 100644 --- a/src/activitystream/object/activity/offer.rs +++ b/src/activitystream/object/activity/offer.rs @@ -12,5 +12,5 @@ pub trait Offer : super::Activity { } pub trait OfferMut : super::ActivityMut { - fn set_offer_type(&mut self, val: Option) -> &mut Self; + fn set_offer_type(self, val: Option) -> Self; } diff --git a/src/activitystream/object/activity/reject.rs b/src/activitystream/object/activity/reject.rs index 01e49a36..ed18ffa5 100644 --- a/src/activitystream/object/activity/reject.rs +++ b/src/activitystream/object/activity/reject.rs @@ -12,5 +12,5 @@ pub trait Reject : super::Activity { } pub trait RejectMut : super::ActivityMut { - fn set_reject_type(&mut self, val: Option) -> &mut Self; + fn set_reject_type(self, val: Option) -> Self; } diff --git a/src/activitystream/object/actor.rs b/src/activitystream/object/actor.rs index 4e493446..016847c7 100644 --- a/src/activitystream/object/actor.rs +++ b/src/activitystream/object/actor.rs @@ -25,15 +25,15 @@ pub trait Actor : super::Object { } pub trait ActorMut : super::ObjectMut { - fn set_actor_type(&mut self, val: Option) -> &mut Self; - fn set_preferred_username(&mut self, val: Option<&str>) -> &mut Self; - fn set_inbox(&mut self, val: Node) -> &mut Self; - fn set_outbox(&mut self, val: Node) -> &mut Self; - fn set_following(&mut self, val: Node) -> &mut Self; - fn set_followers(&mut self, val: Node) -> &mut Self; - fn set_liked(&mut self, val: Node) -> &mut Self; - fn set_streams(&mut self, val: Node) -> &mut Self; - fn set_endpoints(&mut self, val: Option>) -> &mut Self; + fn set_actor_type(self, val: Option) -> Self; + fn set_preferred_username(self, val: Option<&str>) -> Self; + fn set_inbox(self, val: Node) -> Self; + fn set_outbox(self, val: Node) -> Self; + fn set_following(self, val: Node) -> Self; + fn set_followers(self, val: Node) -> Self; + fn set_liked(self, val: Node) -> Self; + fn set_streams(self, val: Node) -> Self; + fn set_endpoints(self, val: Option>) -> Self; } impl Actor for serde_json::Value { @@ -61,7 +61,7 @@ impl ActorMut for serde_json::Value { setter! { liked -> node impl Collection } setter! { streams -> node impl Collection } - fn set_endpoints(&mut self, val: Option>) -> &mut Self { + fn set_endpoints(self, _val: Option>) -> Self { todo!() } } diff --git a/src/activitystream/object/collection/mod.rs b/src/activitystream/object/collection/mod.rs index 14bdc2a8..8be3595a 100644 --- a/src/activitystream/object/collection/mod.rs +++ b/src/activitystream/object/collection/mod.rs @@ -25,14 +25,13 @@ pub trait Collection : super::Object { } pub trait CollectionMut : super::ObjectMut { - fn set_collection_type(&mut self, val: Option) -> &mut Self; - - fn set_total_items(&mut self, val: Option) -> &mut Self; - fn set_current(&mut self, val: Node) -> &mut Self; - fn set_first(&mut self, val: Node) -> &mut Self; - fn set_last(&mut self, val: Node) -> &mut Self; - fn set_items(&mut self, val: Node) -> &mut Self; - fn set_ordered_items(&mut self, val: Node) -> &mut Self; + fn set_collection_type(self, val: Option) -> Self; + fn set_total_items(self, val: Option) -> Self; + fn set_current(self, val: Node) -> Self; + fn set_first(self, val: Node) -> Self; + fn set_last(self, val: Node) -> Self; + fn set_items(self, val: Node) -> Self; + fn set_ordered_items(self, val: Node) -> Self; } impl Collection for serde_json::Value { diff --git a/src/activitystream/object/collection/page.rs b/src/activitystream/object/collection/page.rs index 49a36359..237d83f0 100644 --- a/src/activitystream/object/collection/page.rs +++ b/src/activitystream/object/collection/page.rs @@ -7,9 +7,9 @@ pub trait CollectionPage : super::Collection { } pub trait CollectionPageMut : super::CollectionMut { - fn set_part_of(&mut self, val: Node) -> &mut Self; - fn set_next(&mut self, val: Node) -> &mut Self; - fn set_prev(&mut self, val: Node) -> &mut Self; + fn set_part_of(self, val: Node) -> Self; + fn set_next(self, val: Node) -> Self; + fn set_prev(self, val: Node) -> Self; } impl CollectionPage for serde_json::Value { diff --git a/src/activitystream/object/document.rs b/src/activitystream/object/document.rs index 632105d8..d3f24715 100644 --- a/src/activitystream/object/document.rs +++ b/src/activitystream/object/document.rs @@ -15,13 +15,10 @@ pub trait Document : super::Object { } pub trait DocumentMut : super::ObjectMut { - fn set_document_type(&mut self, val: Option) -> &mut Self; + fn set_document_type(self, val: Option) -> Self; } pub trait Image : Document {} - - impl Document for serde_json::Value {} impl Image for serde_json::Value {} - diff --git a/src/activitystream/object/mod.rs b/src/activitystream/object/mod.rs index 815f8c33..dc6c98d6 100644 --- a/src/activitystream/object/mod.rs +++ b/src/activitystream/object/mod.rs @@ -9,7 +9,7 @@ pub mod relationship; use crate::{getter, setter, strenum}; -use super::Node; +use super::{Link, Node}; use actor::{Actor, ActorType}; use document::{Image, DocumentType}; @@ -56,42 +56,42 @@ pub trait Object : super::Base { fn tag(&self) -> Node { Node::Empty:: } fn updated(&self) -> Option> { None } fn url(&self) -> Option> { None::> } - fn to(&self) -> Node { Node::Empty:: } - fn bto(&self) -> Node { Node::Empty:: } - fn cc(&self) -> Node { Node::Empty:: } - fn bcc(&self) -> Node { Node::Empty:: } + fn to(&self) -> Node { Node::Empty:: } + fn bto(&self) -> Node { Node::Empty:: } + fn cc(&self) -> Node { Node::Empty:: } + fn bcc(&self) -> Node { Node::Empty:: } fn media_type(&self) -> Option<&str> { None } // also in link fn duration(&self) -> Option<&str> { None } // TODO how to parse xsd:duration ? } pub trait ObjectMut : super::BaseMut { - fn set_object_type(&mut self, val: Option) -> &mut Self; - fn set_attachment(&mut self, val: Node) -> &mut Self; - fn set_attributed_to(&mut self, val: Node) -> &mut Self; - fn set_audience(&mut self, val: Node) -> &mut Self; - fn set_content(&mut self, val: Option<&str>) -> &mut Self; // TODO handle language maps - fn set_context(&mut self, val: Node) -> &mut Self; - fn set_name(&mut self, val: Option<&str>) -> &mut Self; // also in link // TODO handle language maps - fn set_end_time(&mut self, val: Option>) -> &mut Self; - fn set_generator(&mut self, val: Node) -> &mut Self; - fn set_icon(&mut self, val: Node) -> &mut Self; - fn set_image(&mut self, val: Node) -> &mut Self; - fn set_in_reply_to(&mut self, val: Node) -> &mut Self; - fn set_location(&mut self, val: Node) -> &mut Self; - fn set_preview(&mut self, val: Node) -> &mut Self; // also in link - fn set_published(&mut self, val: Option>) -> &mut Self; - fn set_replies(&mut self, val: Node) -> &mut Self; - fn set_start_time(&mut self, val: Option>) -> &mut Self; - fn set_summary(&mut self, val: Option<&str>) -> &mut Self; - fn set_tag(&mut self, val: Node) -> &mut Self; - fn set_updated(&mut self, val: Option>) -> &mut Self; - fn set_url(&mut self, val: Option>) -> &mut Self; - fn set_to(&mut self, val: Node) -> &mut Self; - fn set_bto(&mut self, val: Node) -> &mut Self; - fn set_cc(&mut self, val: Node) -> &mut Self; - fn set_bcc(&mut self, val: Node) -> &mut Self; - fn set_media_type(&mut self, val: Option<&str>) -> &mut Self; // also in link - fn set_duration(&mut self, val: Option<&str>) -> &mut Self; // TODO how to parse xsd:duration ? + fn set_object_type(self, val: Option) -> Self; + fn set_attachment(self, val: Node) -> Self; + fn set_attributed_to(self, val: Node) -> Self; + fn set_audience(self, val: Node) -> Self; + fn set_content(self, val: Option<&str>) -> Self; // TODO handle language maps + fn set_context(self, val: Node) -> Self; + fn set_name(self, val: Option<&str>) -> Self; // also in link // TODO handle language maps + fn set_end_time(self, val: Option>) -> Self; + fn set_generator(self, val: Node) -> Self; + fn set_icon(self, val: Node) -> Self; + fn set_image(self, val: Node) -> Self; + fn set_in_reply_to(self, val: Node) -> Self; + fn set_location(self, val: Node) -> Self; + fn set_preview(self, val: Node) -> Self; // also in link + fn set_published(self, val: Option>) -> Self; + fn set_replies(self, val: Node) -> Self; + fn set_start_time(self, val: Option>) -> Self; + fn set_summary(self, val: Option<&str>) -> Self; + fn set_tag(self, val: Node) -> Self; + fn set_updated(self, val: Option>) -> Self; + fn set_url(self, val: Option>) -> Self; + fn set_to(self, val: Node) -> Self; + fn set_bto(self, val: Node) -> Self; + fn set_cc(self, val: Node) -> Self; + fn set_bcc(self, val: Node) -> Self; + fn set_media_type(self, val: Option<&str>) -> Self; // also in link + fn set_duration(self, val: Option<&str>) -> Self; // TODO how to parse xsd:duration ? } impl Object for serde_json::Value { @@ -116,10 +116,10 @@ impl Object for serde_json::Value { getter! { summary -> &str } getter! { tag -> node impl Object } getter! { updated -> chrono::DateTime } - getter! { to -> node impl Object } - getter! { bto -> node impl Object } - getter! { cc -> node impl Object } - getter! { bcc -> node impl Object } + getter! { to -> node impl Link } + getter! { bto -> node impl Link } + getter! { cc -> node impl Link } + getter! { bcc -> node impl Link } getter! { media_type -> &str } getter! { duration -> &str } @@ -155,14 +155,14 @@ impl ObjectMut for serde_json::Value { setter! { summary -> &str } setter! { tag -> node impl Object } setter! { updated -> chrono::DateTime } - setter! { to -> node impl Object } - setter! { bto -> node impl Object} - setter! { cc -> node impl Object } - setter! { bcc -> node impl Object } + setter! { to -> node impl Link } + setter! { bto -> node impl Link} + setter! { cc -> node impl Link } + setter! { bcc -> node impl Link } setter! { media_type -> &str } setter! { duration -> &str } - fn set_url(&mut self, _val: Option>) -> &mut Self { + fn set_url(self, _val: Option>) -> Self { todo!() } } diff --git a/src/activitystream/object/place.rs b/src/activitystream/object/place.rs index 9c63f35e..7fb9bada 100644 --- a/src/activitystream/object/place.rs +++ b/src/activitystream/object/place.rs @@ -8,10 +8,10 @@ pub trait Place : super::Object { } pub trait PlaceMut : super::ObjectMut { - fn set_accuracy(&mut self, val: Option) -> &mut Self; - fn set_altitude(&mut self, val: Option) -> &mut Self; - fn set_latitude(&mut self, val: Option) -> &mut Self; - fn set_longitude(&mut self, val: Option) -> &mut Self; - fn set_radius(&mut self, val: Option) -> &mut Self; - fn set_units(&mut self, val: Option<&str>) -> &mut Self; + fn set_accuracy(self, val: Option) -> Self; + fn set_altitude(self, val: Option) -> Self; + fn set_latitude(self, val: Option) -> Self; + fn set_longitude(self, val: Option) -> Self; + fn set_radius(self, val: Option) -> Self; + fn set_units(self, val: Option<&str>) -> Self; } diff --git a/src/activitystream/object/relationship.rs b/src/activitystream/object/relationship.rs index 52aa6de9..7d69f9d2 100644 --- a/src/activitystream/object/relationship.rs +++ b/src/activitystream/object/relationship.rs @@ -7,9 +7,9 @@ pub trait Relationship : super::Object { } pub trait RelationshipMut : super::ObjectMut { - fn set_subject(&mut self, val: Node) -> &mut Self; - fn set_relationship(&mut self, val: Option<&str>) -> &mut Self; // TODO what does this mean??? - fn set_object(&mut self, val: Node) -> &mut Self; + fn set_subject(self, val: Node) -> Self; + fn set_relationship(self, val: Option<&str>) -> Self; // TODO what does this mean??? + fn set_object(self, val: Node) -> Self; } impl Relationship for serde_json::Value { diff --git a/src/activitystream/object/tombstone.rs b/src/activitystream/object/tombstone.rs index 368e8135..7216c215 100644 --- a/src/activitystream/object/tombstone.rs +++ b/src/activitystream/object/tombstone.rs @@ -4,8 +4,8 @@ pub trait Tombstone : super::Object { } pub trait TombstoneMut : super::ObjectMut { - fn set_former_type(&mut self, val: Option) -> &mut Self; - fn set_deleted(&mut self, val: Option>) -> &mut Self; + fn set_former_type(self, val: Option) -> Self; + fn set_deleted(self, val: Option>) -> Self; } impl Tombstone for serde_json::Value {