Use Url's native Serde support

This commit is contained in:
asonix 2020-06-27 17:21:35 -05:00
parent df49fcd1a7
commit 60716a6d2a
7 changed files with 85 additions and 109 deletions

View file

@ -17,7 +17,7 @@ mime = "0.3"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "1.0" thiserror = "1.0"
url = "2.1" url = { version = "2.1", features = ["serde"] }
[dev-dependencies] [dev-dependencies]
anyhow = "1.0" anyhow = "1.0"

View file

@ -26,7 +26,7 @@ use crate::{
error::DomainError, error::DomainError,
markers, markers,
object::{ApObject, AsApObject, AsObject, Object}, object::{ApObject, AsApObject, AsObject, Object},
primitives::{OneOrMany, XsdAnyUri}, primitives::OneOrMany,
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt}, unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
}; };
use url::Url; use url::Url;
@ -108,7 +108,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_ref().inbox.as_ref() &self.ap_actor_ref().inbox
} }
/// Fetch a mutable referece to the current actor's inbox /// Fetch a mutable referece to the current actor's inbox
@ -125,7 +125,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_mut().inbox.as_mut() &mut self.ap_actor_mut().inbox
} }
/// Set the inbox for the current actor /// Set the inbox for the current actor
@ -188,7 +188,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_ref().outbox.as_ref().map(|u| u.as_ref()) self.ap_actor_ref().outbox.as_ref()
} }
/// Mutably fetch the outbox for the current actor /// Mutably fetch the outbox for the current actor
@ -207,7 +207,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_mut().outbox.as_mut().map(|u| u.as_mut()) self.ap_actor_mut().outbox.as_mut()
} }
/// Set the outbox for the current actor /// Set the outbox for the current actor
@ -239,7 +239,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// } /// }
/// ``` /// ```
fn take_outbox(&mut self) -> Option<Url> { fn take_outbox(&mut self) -> Option<Url> {
self.ap_actor_mut().outbox.take().map(|u| u.into_inner()) self.ap_actor_mut().outbox.take()
} }
/// Delete the outbox from the current object /// Delete the outbox from the current object
@ -309,7 +309,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_ref().following.as_ref().map(|f| f.as_ref()) self.ap_actor_ref().following.as_ref()
} }
/// Mutably fetch the following link for the current actor /// Mutably fetch the following link for the current actor
@ -328,7 +328,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_mut().following.as_mut().map(|f| f.as_mut()) self.ap_actor_mut().following.as_mut()
} }
/// Set the following link for the current actor /// Set the following link for the current actor
@ -360,7 +360,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// } /// }
/// ``` /// ```
fn take_following(&mut self) -> Option<Url> { fn take_following(&mut self) -> Option<Url> {
self.ap_actor_mut().following.take().map(|u| u.into_inner()) self.ap_actor_mut().following.take()
} }
/// Delete the following link from the current object /// Delete the following link from the current object
@ -430,7 +430,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_ref().followers.as_ref().map(|u| u.as_ref()) self.ap_actor_ref().followers.as_ref()
} }
/// Mutably fetch the followers link for the current actor /// Mutably fetch the followers link for the current actor
@ -449,7 +449,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_mut().followers.as_mut().map(|u| u.as_mut()) self.ap_actor_mut().followers.as_mut()
} }
/// Set the followers link for the current actor /// Set the followers link for the current actor
@ -481,7 +481,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// } /// }
/// ``` /// ```
fn take_followers(&mut self) -> Option<Url> { fn take_followers(&mut self) -> Option<Url> {
self.ap_actor_mut().followers.take().map(|u| u.into_inner()) self.ap_actor_mut().followers.take()
} }
/// Delete the followers link from the current object /// Delete the followers link from the current object
@ -551,7 +551,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_ref().liked.as_ref().map(|u| u.as_ref()) self.ap_actor_ref().liked.as_ref()
} }
/// Mutably fetch the liked link for the current actor /// Mutably fetch the liked link for the current actor
@ -570,7 +570,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_mut().liked.as_mut().map(|u| u.as_mut()) self.ap_actor_mut().liked.as_mut()
} }
/// Set the liked link for the current actor /// Set the liked link for the current actor
@ -602,7 +602,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// } /// }
/// ``` /// ```
fn take_liked(&mut self) -> Option<Url> { fn take_liked(&mut self) -> Option<Url> {
self.ap_actor_mut().liked.take().map(|u| u.into_inner()) self.ap_actor_mut().liked.take()
} }
/// Delete the liked link from the current object /// Delete the liked link from the current object
@ -684,10 +684,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_ref() self.ap_actor_ref().streams.as_ref().map(|o| o.as_ref())
.streams
.as_ref()
.map(|o| o.as_ref().map(|u| u.as_ref()))
} }
/// Mutably fetch the streams links for the current actor /// Mutably fetch the streams links for the current actor
@ -711,10 +708,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_mut() self.ap_actor_mut().streams.as_mut().map(|o| o.as_mut())
.streams
.as_mut()
.map(|o| o.as_mut().map(|u| u.as_mut()))
} }
/// Set the streams links for the current actor /// Set the streams links for the current actor
@ -730,7 +724,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// # } /// # }
/// ``` /// ```
fn set_streams(&mut self, streams: Url) -> &mut Self { fn set_streams(&mut self, streams: Url) -> &mut Self {
self.ap_actor_mut().streams = Some(XsdAnyUri::from(streams).into()); self.ap_actor_mut().streams = Some(streams.into());
self self
} }
@ -749,11 +743,12 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
fn set_many_streams<I>(&mut self, items: I) -> &mut Self fn set_many_streams<I, U>(&mut self, items: I) -> &mut Self
where where
I: IntoIterator<Item = Url>, I: IntoIterator<Item = U>,
U: Into<Url>,
{ {
let v: Vec<XsdAnyUri> = items.into_iter().map(|u| u.into()).collect(); let v: Vec<Url> = items.into_iter().map(|u| u.into()).collect();
self.ap_actor_mut().streams = Some(v.into()); self.ap_actor_mut().streams = Some(v.into());
self self
} }
@ -775,7 +770,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
fn add_streams(&mut self, stream: Url) -> &mut Self { fn add_streams(&mut self, stream: Url) -> &mut Self {
let v = match self.ap_actor_mut().streams.take() { let v = match self.ap_actor_mut().streams.take() {
Some(mut v) => { Some(mut v) => {
v.add(XsdAnyUri::from(stream)); v.add(stream);
v v
} }
None => vec![stream.into()].into(), None => vec![stream.into()].into(),
@ -796,10 +791,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// } /// }
/// ``` /// ```
fn take_streams(&mut self) -> Option<OneOrMany<Url>> { fn take_streams(&mut self) -> Option<OneOrMany<Url>> {
self.ap_actor_mut() self.ap_actor_mut().streams.take()
.streams
.take()
.map(|o| o.map(|u| u.into_inner()))
} }
/// Delete the streams links from the current object /// Delete the streams links from the current object
@ -975,10 +967,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_ref() self.ap_actor_ref().endpoints.as_ref().map(|e| e.as_ref())
.endpoints
.as_ref()
.map(|e| e.as_ref().map(|u| u.as_ref()))
} }
/// Mutably fetch the endpoints for the current actor /// Mutably fetch the endpoints for the current actor
@ -997,10 +986,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_actor_mut() self.ap_actor_mut().endpoints.as_mut().map(|e| e.as_mut())
.endpoints
.as_mut()
.map(|e| e.as_mut().map(|u| u.as_mut()))
} }
/// Set the endpoints for the current actor /// Set the endpoints for the current actor
@ -1035,10 +1021,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// } /// }
/// ``` /// ```
fn take_endpoints(&mut self) -> Option<Endpoints<Url>> { fn take_endpoints(&mut self) -> Option<Endpoints<Url>> {
self.ap_actor_mut() self.ap_actor_mut().endpoints.take()
.endpoints
.take()
.map(|e| e.map(|u| u.into_inner()))
} }
/// Delete the endpoints from the current actor /// Delete the endpoints from the current actor
@ -1114,42 +1097,42 @@ pub struct ApActor<Inner> {
/// ///
/// - Range: xsd:anyUri /// - Range: xsd:anyUri
/// - Functional: true /// - Functional: true
inbox: XsdAnyUri, inbox: Url,
/// An ActivityStreams] OrderedCollection comprised of all the messages produced by the actor. /// An ActivityStreams] OrderedCollection comprised of all the messages produced by the actor.
/// ///
/// - Range: xsd:anyUri /// - Range: xsd:anyUri
/// - Functional: true /// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
outbox: Option<XsdAnyUri>, outbox: Option<Url>,
/// A link to an [ActivityStreams] collection of the actors that this actor is following. /// A link to an [ActivityStreams] collection of the actors that this actor is following.
/// ///
/// - Range: xsd:anyUri /// - Range: xsd:anyUri
/// - Functional: true /// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
following: Option<XsdAnyUri>, following: Option<Url>,
/// A link to an [ActivityStreams] collection of the actors that follow this actor. /// A link to an [ActivityStreams] collection of the actors that follow this actor.
/// ///
/// - Range: xsd:anyUri /// - Range: xsd:anyUri
/// - Functional: true /// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
followers: Option<XsdAnyUri>, followers: Option<Url>,
/// A link to an [ActivityStreams] collection of objects this actor has liked. /// A link to an [ActivityStreams] collection of objects this actor has liked.
/// ///
/// - Range: xsd:anyUri /// - Range: xsd:anyUri
/// - Functional: true /// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
liked: Option<XsdAnyUri>, liked: Option<Url>,
/// A list of supplementary Collections which may be of interest. /// A list of supplementary Collections which may be of interest.
/// ///
/// - Range: xsd:anyUri /// - Range: xsd:anyUri
/// - Functional: false /// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
streams: Option<OneOrMany<XsdAnyUri>>, streams: Option<OneOrMany<Url>>,
/// A short username which may be used to refer to the actor, with no uniqueness guarantees. /// A short username which may be used to refer to the actor, with no uniqueness guarantees.
/// ///
@ -1167,7 +1150,7 @@ pub struct ApActor<Inner> {
/// - Range: Endpoint /// - Range: Endpoint
/// - Functional: true /// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
endpoints: Option<Endpoints<XsdAnyUri>>, endpoints: Option<Endpoints<Url>>,
/// base fields and unparsed json ends up here /// base fields and unparsed json ends up here
#[serde(flatten)] #[serde(flatten)]

View file

@ -31,7 +31,7 @@ use crate::{
either::Either, either::Either,
error::DomainError, error::DomainError,
markers, markers,
primitives::{AnyString, MimeMediaType, OneOrMany, XsdAnyUri}, primitives::{AnyString, MimeMediaType, OneOrMany},
unparsed::{Unparsed, UnparsedMut}, unparsed::{Unparsed, UnparsedMut},
}; };
use mime::Mime; use mime::Mime;
@ -290,7 +290,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
where where
Kind: 'a, Kind: 'a,
{ {
self.base_ref().id.as_ref().map(|i| i.as_ref()) self.base_ref().id.as_ref()
} }
/// Mutably borrow the ID from the current object /// Mutably borrow the ID from the current object
@ -310,7 +310,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
where where
Kind: 'a, Kind: 'a,
{ {
self.base_mut().id.as_mut().map(|i| i.as_mut()) self.base_mut().id.as_mut()
} }
/// Check if the provided id is equal to the object's id /// Check if the provided id is equal to the object's id
@ -362,7 +362,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// } /// }
/// ``` /// ```
fn take_id(&mut self) -> Option<Url> { fn take_id(&mut self) -> Option<Url> {
self.base_mut().id.take().map(|u| u.into_inner()) self.base_mut().id.take()
} }
/// Delete the id from the current object /// Delete the id from the current object
@ -812,7 +812,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(transparent)] #[serde(transparent)]
struct IdOrBase(Either<XsdAnyUri, Box<Base<serde_json::Value>>>); struct IdOrBase(Either<Url, Box<Base<serde_json::Value>>>);
/// A type that can represent Any ActivityStreams type /// A type that can represent Any ActivityStreams type
/// ///
@ -859,7 +859,7 @@ pub struct Base<Kind> {
/// When processing Activity Streams 1.0 documents and converting those to 2.0, implementations /// When processing Activity Streams 1.0 documents and converting those to 2.0, implementations
/// ought to treat id as an alias for the JSON-LD @id key word[.] /// ought to treat id as an alias for the JSON-LD @id key word[.]
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
id: Option<XsdAnyUri>, id: Option<Url>,
/// The `type` field /// The `type` field
/// ///
@ -1089,7 +1089,7 @@ impl AnyBase {
Ok(Base::retract(extended)?.into_generic()?.into()) Ok(Base::retract(extended)?.into_generic()?.into())
} }
/// Check if this object is an XsdAnyUri /// Check if this object is a Url
/// ///
/// ```rust /// ```rust
/// # use activitystreams_new::{base::AnyBase, uri}; /// # use activitystreams_new::{base::AnyBase, uri};
@ -1168,10 +1168,8 @@ impl AnyBase {
/// # } /// # }
/// ``` /// ```
pub fn id(&self) -> Option<&Url> { pub fn id(&self) -> Option<&Url> {
self.as_xsd_any_uri().or_else(|| { self.as_xsd_any_uri()
self.as_base() .or_else(|| self.as_base().and_then(|base| base.id.as_ref()))
.and_then(|base| base.id.as_ref().map(|i| i.as_ref()))
})
} }
/// Check if the current object's id matches the provided id /// Check if the current object's id matches the provided id
@ -1269,7 +1267,7 @@ impl AnyBase {
self.kind_str() == Some(kind) self.kind_str() == Some(kind)
} }
/// Get the object as an XsdAnyUri /// Get the object as a Url
/// ///
/// ```rust /// ```rust
/// # fn main() -> Result<(), anyhow::Error> { /// # fn main() -> Result<(), anyhow::Error> {
@ -1317,7 +1315,7 @@ impl AnyBase {
self.0.as_ref().left().and_then(|l| l.as_base()) self.0.as_ref().left().and_then(|l| l.as_base())
} }
/// Take the XsdAnyUri from the Object /// Take the Url from the Object
/// ///
/// ```rust /// ```rust
/// # fn main() -> Result<(), anyhow::Error> { /// # fn main() -> Result<(), anyhow::Error> {
@ -1365,7 +1363,7 @@ impl AnyBase {
self.0.left().and_then(|l| l.base()) self.0.left().and_then(|l| l.base())
} }
/// Replace the object with the provided XsdAnyUri /// Replace the object with the provided Url
/// ///
/// ```rust /// ```rust
/// # fn main() -> Result<(), anyhow::Error> { /// # fn main() -> Result<(), anyhow::Error> {
@ -1426,7 +1424,7 @@ impl AnyBase {
self.0 = Either::Left(IdOrBase::from_base(base)); self.0 = Either::Left(IdOrBase::from_base(base));
} }
/// Create an AnyBase from an XsdAnyUri /// Create an AnyBase from a Url
/// ///
/// ```rust /// ```rust
/// # fn main() -> Result<(), anyhow::Error> { /// # fn main() -> Result<(), anyhow::Error> {
@ -1469,7 +1467,7 @@ impl AnyBase {
impl IdOrBase { impl IdOrBase {
fn as_xsd_any_uri(&self) -> Option<&Url> { fn as_xsd_any_uri(&self) -> Option<&Url> {
self.0.as_ref().left().map(|u| u.as_ref()) self.0.as_ref().left()
} }
fn as_base(&self) -> Option<&Base<serde_json::Value>> { fn as_base(&self) -> Option<&Base<serde_json::Value>> {
@ -1477,7 +1475,7 @@ impl IdOrBase {
} }
fn id(self) -> Option<Url> { fn id(self) -> Option<Url> {
self.0.left().map(|u| u.into_inner()) self.0.left()
} }
fn base(self) -> Option<Base<serde_json::Value>> { fn base(self) -> Option<Base<serde_json::Value>> {
@ -1485,7 +1483,7 @@ impl IdOrBase {
} }
fn from_xsd_any_uri(id: Url) -> Self { fn from_xsd_any_uri(id: Url) -> Self {
IdOrBase(Either::Left(id.into())) IdOrBase(Either::Left(id))
} }
fn from_base(base: Base<serde_json::Value>) -> Self { fn from_base(base: Base<serde_json::Value>) -> Self {
@ -1584,7 +1582,7 @@ impl OneOrMany<AnyBase> {
self.as_single_kind_str() == Some(kind) self.as_single_kind_str() == Some(kind)
} }
/// Get a single XsdAnyUri from the object, if that is what is contained /// Get a single Url from the object, if that is what is contained
/// ///
/// ```rust /// ```rust
/// # fn main() -> Result<(), anyhow::Error> { /// # fn main() -> Result<(), anyhow::Error> {
@ -1628,7 +1626,7 @@ impl OneOrMany<AnyBase> {
self.as_one().and_then(|inner| inner.as_base()) self.as_one().and_then(|inner| inner.as_base())
} }
/// Take a single XsdAnyUri from the object, if that is what is contained /// Take a single Url from the object, if that is what is contained
/// ///
/// ```rust /// ```rust
/// # fn main() -> Result<(), anyhow::Error> { /// # fn main() -> Result<(), anyhow::Error> {
@ -1672,7 +1670,7 @@ impl OneOrMany<AnyBase> {
self.one().and_then(|inner| inner.take_base()) self.one().and_then(|inner| inner.take_base())
} }
/// Create a `OneOrMany<AnyBase>` from an XsdAnyUri /// Create a `OneOrMany<AnyBase>` from a Url
/// ///
/// ```rust /// ```rust
/// # fn main() -> Result<(), anyhow::Error> { /// # fn main() -> Result<(), anyhow::Error> {
@ -1711,7 +1709,7 @@ impl OneOrMany<AnyBase> {
OneOrMany(Either::Left(AnyBase::from_base(base))) OneOrMany(Either::Left(AnyBase::from_base(base)))
} }
/// Overwrite the current object with an XsdAnyUri /// Overwrite the current object with a Url
/// ///
/// ```rust /// ```rust
/// # use activitystreams_new::{base::Base, context, primitives::OneOrMany}; /// # use activitystreams_new::{base::Base, context, primitives::OneOrMany};
@ -1762,7 +1760,7 @@ impl OneOrMany<AnyBase> {
self self
} }
/// Append an XsdAnyUri to the current object /// Append a Url to the current object
/// ///
/// ```rust /// ```rust
/// use activitystreams_new::{base::AnyBase, context, primitives::OneOrMany, security}; /// use activitystreams_new::{base::AnyBase, context, primitives::OneOrMany, security};

View file

@ -23,7 +23,7 @@
use crate::{ use crate::{
base::{AsBase, Base, Extends}, base::{AsBase, Base, Extends},
markers, markers,
primitives::{OneOrMany, XsdAnyUri}, primitives::OneOrMany,
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt}, unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
}; };
use std::convert::TryFrom; use std::convert::TryFrom;
@ -73,7 +73,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
where where
Kind: 'a, Kind: 'a,
{ {
self.link_ref().href.as_ref().map(|u| u.as_ref()) self.link_ref().href.as_ref()
} }
/// Set the href for the current object /// Set the href for the current object
@ -92,7 +92,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// # } /// # }
/// ``` /// ```
fn set_href(&mut self, href: Url) -> &mut Self { fn set_href(&mut self, href: Url) -> &mut Self {
self.link_mut().href = Some(href.into()); self.link_mut().href = Some(href);
self self
} }
@ -109,7 +109,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// } /// }
/// ``` /// ```
fn take_href(&mut self) -> Option<Url> { fn take_href(&mut self) -> Option<Url> {
self.link_mut().href.take().map(|u| u.into_inner()) self.link_mut().href.take()
} }
/// Delete the href from the current object /// Delete the href from the current object
@ -502,7 +502,7 @@ pub struct Link<Kind> {
/// - Range: xsd:anyUri /// - Range: xsd:anyUri
/// - Functional: true /// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
href: Option<XsdAnyUri>, href: Option<Url>,
/// Hints as to the language used by the target resource. /// Hints as to the language used by the target resource.
/// ///

View file

@ -22,7 +22,7 @@
use crate::{ use crate::{
base::{AnyBase, AsBase, Base, Extends}, base::{AnyBase, AsBase, Base, Extends},
markers, markers,
primitives::{AnyString, OneOrMany, Unit, XsdAnyUri, XsdDateTime, XsdDuration}, primitives::{AnyString, OneOrMany, Unit, XsdDateTime, XsdDuration},
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt}, unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
}; };
use chrono::{DateTime, Duration, FixedOffset}; use chrono::{DateTime, Duration, FixedOffset};
@ -2821,7 +2821,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_object_ref().shares.as_ref().map(|u| u.as_ref()) self.ap_object_ref().shares.as_ref()
} }
/// Set the shares for the current object /// Set the shares for the current object
@ -2857,7 +2857,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// } /// }
/// ``` /// ```
fn take_shares(&mut self) -> Option<Url> { fn take_shares(&mut self) -> Option<Url> {
self.ap_object_mut().shares.take().map(|u| u.into_inner()) self.ap_object_mut().shares.take()
} }
/// Delete the shares from the current object /// Delete the shares from the current object
@ -2894,7 +2894,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
where where
Inner: 'a, Inner: 'a,
{ {
self.ap_object_ref().likes.as_ref().map(|u| u.as_ref()) self.ap_object_ref().likes.as_ref()
} }
/// Set the likes for the current object /// Set the likes for the current object
@ -2930,7 +2930,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// } /// }
/// ``` /// ```
fn take_likes(&mut self) -> Option<Url> { fn take_likes(&mut self) -> Option<Url> {
self.ap_object_mut().likes.take().map(|u| u.into_inner()) self.ap_object_mut().likes.take()
} }
/// Delete the likes from the current object /// Delete the likes from the current object
@ -3046,7 +3046,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
self.ap_object_ref() self.ap_object_ref()
.upload_media .upload_media
.as_ref() .as_ref()
.map(|o| o.as_ref().map(|u| u.as_ref())) .map(|o| o.as_ref())
} }
/// Set the upload_media for the current object /// Set the upload_media for the current object
@ -3065,7 +3065,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// # } /// # }
/// ``` /// ```
fn set_upload_media(&mut self, upload_media: Url) -> &mut Self { fn set_upload_media(&mut self, upload_media: Url) -> &mut Self {
self.ap_object_mut().upload_media = Some(XsdAnyUri::from(upload_media).into()); self.ap_object_mut().upload_media = Some(upload_media.into());
self self
} }
@ -3087,11 +3087,12 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
fn set_many_upload_medias<I>(&mut self, items: I) -> &mut Self fn set_many_upload_medias<I, U>(&mut self, items: I) -> &mut Self
where where
I: IntoIterator<Item = Url>, I: IntoIterator<Item = U>,
U: Into<Url>,
{ {
let v: Vec<XsdAnyUri> = items.into_iter().map(|u| u.into()).collect(); let v: Vec<Url> = items.into_iter().map(|u| u.into()).collect();
self.ap_object_mut().upload_media = Some(v.into()); self.ap_object_mut().upload_media = Some(v.into());
self self
} }
@ -3116,7 +3117,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
fn add_upload_media(&mut self, upload_media: Url) -> &mut Self { fn add_upload_media(&mut self, upload_media: Url) -> &mut Self {
let v = match self.ap_object_mut().upload_media.take() { let v = match self.ap_object_mut().upload_media.take() {
Some(mut v) => { Some(mut v) => {
v.add(XsdAnyUri::from(upload_media)); v.add(upload_media);
v v
} }
None => vec![upload_media.into()].into(), None => vec![upload_media.into()].into(),
@ -3138,10 +3139,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// } /// }
/// ``` /// ```
fn take_upload_media(&mut self) -> Option<OneOrMany<Url>> { fn take_upload_media(&mut self) -> Option<OneOrMany<Url>> {
self.ap_object_mut() self.ap_object_mut().upload_media.take()
.upload_media
.take()
.map(|o| o.map(|u| u.into_inner()))
} }
/// Delete the upload_media from the current object /// Delete the upload_media from the current object
@ -4494,7 +4492,7 @@ pub struct ApObject<Inner> {
/// - Range: anyUri /// - Range: anyUri
/// - Functional: true /// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
shares: Option<XsdAnyUri>, shares: Option<Url>,
/// This is a list of all Like activities with this object as the object property, added as a /// This is a list of all Like activities with this object as the object property, added as a
/// side effect. /// side effect.
@ -4506,7 +4504,7 @@ pub struct ApObject<Inner> {
/// - Range: anyUri /// - Range: anyUri
/// - Functional: true /// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
likes: Option<XsdAnyUri>, likes: Option<Url>,
/// The source property is intended to convey some sort of source from which the content markup /// The source property is intended to convey some sort of source from which the content markup
/// was derived, as a form of provenance, or to support future editing by clients. /// was derived, as a form of provenance, or to support future editing by clients.
@ -4531,7 +4529,7 @@ pub struct ApObject<Inner> {
/// - Range: anyUri /// - Range: anyUri
/// - Functional: false /// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
upload_media: Option<OneOrMany<XsdAnyUri>>, upload_media: Option<OneOrMany<Url>>,
/// The ActivityStreams object being extended /// The ActivityStreams object being extended
#[serde(flatten)] #[serde(flatten)]

View file

@ -32,8 +32,5 @@ pub use self::{
use self::serde_parse::SerdeParse; use self::serde_parse::SerdeParse;
/// An alias for the url::Url struct with serde compatibility
pub type XsdAnyUri = SerdeParse<url::Url>;
/// An alias for the mime::Mime struct with serde compatibility /// An alias for the mime::Mime struct with serde compatibility
pub(crate) type MimeMediaType = SerdeParse<mime::Mime>; pub(crate) type MimeMediaType = SerdeParse<mime::Mime>;

View file

@ -31,8 +31,8 @@
//! #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] //! #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
//! #[serde(rename_all = "camelCase")] //! #[serde(rename_all = "camelCase")]
//! pub struct PublicKeyValues { //! pub struct PublicKeyValues {
//! pub id: XsdAnyUri, //! pub id: Url,
//! pub owner: XsdAnyUri, //! pub owner: Url,
//! pub public_key_pem: String, //! pub public_key_pem: String,
//! } //! }
//! //!
@ -172,12 +172,12 @@
//! where //! where
//! Inner: 'a, //! Inner: 'a,
//! { //! {
//! &self.public_key_ref().public_key.id.as_ref() //! &self.public_key_ref().public_key.id
//! } //! }
//! //!
//! /// Set the public key's ID //! /// Set the public key's ID
//! fn set_key_id(&mut self, id: Url) -> &mut Self { //! fn set_key_id(&mut self, id: Url) -> &mut Self {
//! self.public_key_mut().public_key.id = id.into(); //! self.public_key_mut().public_key.id = id;
//! self //! self
//! } //! }
//! //!
@ -186,12 +186,12 @@
//! where //! where
//! Inner: 'a, //! Inner: 'a,
//! { //! {
//! &self.public_key_ref().public_key.owner.as_ref() //! &self.public_key_ref().public_key.owner
//! } //! }
//! //!
//! /// Set the public key's Owner //! /// Set the public key's Owner
//! fn set_key_owner(&mut self, owner: Url) -> &mut Self { //! fn set_key_owner(&mut self, owner: Url) -> &mut Self {
//! self.public_key_mut().public_key.owner = owner.into(); //! self.public_key_mut().public_key.owner = owner;
//! self //! self
//! } //! }
//! //!
@ -231,8 +231,8 @@
//! owner.set_fragment(Some("main-key")); //! owner.set_fragment(Some("main-key"));
//! PublicKey { //! PublicKey {
//! public_key: PublicKeyValues { //! public_key: PublicKeyValues {
//! id: id.into(), //! id,
//! owner: owner.into(), //! owner,
//! public_key_pem: String::new(), //! public_key_pem: String::new(),
//! }, //! },
//! inner: ApActor::new(inbox, Person::new()), //! inner: ApActor::new(inbox, Person::new()),