mirror of
https://git.asonix.dog/asonix/activitystreams.git
synced 2024-11-22 03:40:59 +00:00
Migrate to IriString
This commit is contained in:
parent
fe84059d00
commit
245904d078
16 changed files with 808 additions and 1066 deletions
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "activitystreams"
|
name = "activitystreams"
|
||||||
description = "A set of core types and traits for activitystreams data"
|
description = "A set of core types and traits for activitystreams data"
|
||||||
version = "0.7.0-alpha.14"
|
version = "0.7.0-alpha.15"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
authors = ["asonix <asonix@asonix.dog>"]
|
authors = ["asonix <asonix@asonix.dog>"]
|
||||||
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
|
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
|
||||||
|
@ -19,13 +19,13 @@ members = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
activitystreams-kinds = { version = "0.1.0", path = "./activitystreams-kinds/" }
|
activitystreams-kinds = { version = "0.1.0", path = "./activitystreams-kinds/", default-features = false, features = ["iri-string"] }
|
||||||
chrono = "0.4"
|
iri-string = { version = "0.4.1", features = ["serde", "serde-std"] }
|
||||||
mime = "0.3"
|
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 = { version = "2.1", features = ["serde"] }
|
time = { version = "0.3.5", features = ["formatting", "parsing"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
|
|
@ -11,9 +11,13 @@ edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["url"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
url = "2"
|
url = { version = "2", optional = true }
|
||||||
|
iri-string = { version = "0.4.1", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
|
|
|
@ -2,13 +2,16 @@
|
||||||
//!
|
//!
|
||||||
//! Enums representing typed versions of activitypub 'type' fields.
|
//! Enums representing typed versions of activitypub 'type' fields.
|
||||||
|
|
||||||
|
#[cfg(feature = "url")]
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
#[cfg(feature = "url")]
|
||||||
/// Returns the `https://www.w3.org/ns/activitystreams` Url
|
/// Returns the `https://www.w3.org/ns/activitystreams` Url
|
||||||
pub fn context() -> Url {
|
pub fn context() -> Url {
|
||||||
"https://www.w3.org/ns/activitystreams".parse().unwrap()
|
"https://www.w3.org/ns/activitystreams".parse().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "url")]
|
||||||
/// Returns the `https://www.w3.org/ns/activitystreams#Public` Url
|
/// Returns the `https://www.w3.org/ns/activitystreams#Public` Url
|
||||||
pub fn public() -> Url {
|
pub fn public() -> Url {
|
||||||
"https://www.w3.org/ns/activitystreams#Public"
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
@ -16,11 +19,32 @@ pub fn public() -> Url {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "url")]
|
||||||
/// Returns the `https://w3id.org/security/v1` Url
|
/// Returns the `https://w3id.org/security/v1` Url
|
||||||
pub fn security() -> Url {
|
pub fn security() -> Url {
|
||||||
"https://w3id.org/security/v1".parse().unwrap()
|
"https://w3id.org/security/v1".parse().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "iri-string")]
|
||||||
|
/// Returns the `https://www.w3.org/ns/activitystreams` IRI
|
||||||
|
pub fn context_iri() -> iri_string::types::IriString {
|
||||||
|
"https://www.w3.org/ns/activitystreams".parse().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "iri-string")]
|
||||||
|
/// Returns the `https://www.w3.org/ns/activitystreams#Public` IRI
|
||||||
|
pub fn public_iri() -> iri_string::types::IriString {
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
.parse()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "iri-string")]
|
||||||
|
/// Returns the `https://w3id.org/security/v1` IRI
|
||||||
|
pub fn security_iri() -> iri_string::types::IriString {
|
||||||
|
"https://w3id.org/security/v1".parse().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
/// Generate an enum implementing serde's Serialize and Deserialize with a single variant
|
/// Generate an enum implementing serde's Serialize and Deserialize with a single variant
|
||||||
///
|
///
|
||||||
/// This is useful for describing constants
|
/// This is useful for describing constants
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
context,
|
context, iri,
|
||||||
object::{ApObject, Video},
|
object::{ApObject, Video},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
uri,
|
|
||||||
};
|
};
|
||||||
use chrono::Duration;
|
use time::Duration;
|
||||||
|
|
||||||
fn main() -> Result<(), anyhow::Error> {
|
fn main() -> Result<(), anyhow::Error> {
|
||||||
let mut video = ApObject::new(Video::new());
|
let mut video = ApObject::new(Video::new());
|
||||||
|
|
||||||
video
|
video
|
||||||
.set_context(context())
|
.set_context(context())
|
||||||
.set_id(uri!("https://example.com/@example/lions"))
|
.set_id(iri!("https://example.com/@example/lions"))
|
||||||
.set_media_type("video/webm".parse()?)
|
.set_media_type("video/webm".parse()?)
|
||||||
.set_url(uri!("https://example.com/@example/lions/video.webm"))
|
.set_url(iri!("https://example.com/@example/lions/video.webm"))
|
||||||
.set_summary("A cool video".to_owned())
|
.set_summary("A cool video".to_owned())
|
||||||
.set_duration(Duration::minutes(4) + Duration::seconds(20))
|
.set_duration(Duration::minutes(4) + Duration::seconds(20))
|
||||||
.set_shares(uri!("https://example.com/@example/lions/video.webm#shares"));
|
.set_shares(iri!("https://example.com/@example/lions/video.webm#shares"));
|
||||||
|
|
||||||
println!("Video, {:#?}", video);
|
println!("Video, {:#?}", video);
|
||||||
|
|
||||||
|
|
245
src/activity.rs
245
src/activity.rs
|
@ -6,32 +6,31 @@
|
||||||
//! activity::Create,
|
//! activity::Create,
|
||||||
//! context,
|
//! context,
|
||||||
//! prelude::*,
|
//! prelude::*,
|
||||||
//! uri,
|
//! iri,
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
//! let mut create = Create::new(
|
//! let mut create = Create::new(
|
||||||
//! uri!("https://example.com/actors/abcd"),
|
//! iri!("https://example.com/actors/abcd"),
|
||||||
//! uri!("https://example.com/notes/1234"),
|
//! iri!("https://example.com/notes/1234"),
|
||||||
//! );
|
//! );
|
||||||
//!
|
//!
|
||||||
//! create
|
//! create
|
||||||
//! .set_result(uri!("https://example.com/"))
|
//! .set_result(iri!("https://example.com/"))
|
||||||
//! .set_instrument(uri!("https://example.com/"))
|
//! .set_instrument(iri!("https://example.com/"))
|
||||||
//! .set_id(uri!("https://example.com/activities/abcd"))
|
//! .set_id(iri!("https://example.com/activities/abcd"))
|
||||||
//! .set_context(context());
|
//! .set_context(context());
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
use crate::{
|
use crate::{
|
||||||
base::{AnyBase, AsBase, Base, BaseExt, Extends},
|
base::{AnyBase, AsBase, Base, Extends},
|
||||||
error::DomainError,
|
|
||||||
markers,
|
markers,
|
||||||
object::{ApObject, AsObject, Object},
|
object::{ApObject, AsObject, Object},
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
|
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
|
||||||
};
|
};
|
||||||
|
use iri_string::types::IriString;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
pub use activitystreams_kinds::activity as kind;
|
pub use activitystreams_kinds::activity as kind;
|
||||||
|
|
||||||
|
@ -158,10 +157,10 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question.set_result(uri!("https://example.com"));
|
/// question.set_result(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -180,12 +179,12 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question.set_many_results(vec![
|
/// question.set_many_results(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -206,13 +205,13 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, iri};
|
||||||
/// # use activitystreams::{activity::Question};
|
/// # use activitystreams::{activity::Question};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question
|
/// question
|
||||||
/// .add_result(uri!("https://example.com/one"))
|
/// .add_result(iri!("https://example.com/one"))
|
||||||
/// .add_result(uri!("https://example.com/two"));
|
/// .add_result(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -251,9 +250,9 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
/// # question.set_result(uri!("https://example.com"));
|
/// # question.set_result(iri!("https://example.com"));
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -294,10 +293,10 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question.set_instrument(uri!("https://example.com"));
|
/// question.set_instrument(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -316,12 +315,12 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question.set_many_instruments(vec![
|
/// question.set_many_instruments(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -343,12 +342,12 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question
|
/// question
|
||||||
/// .add_instrument(uri!("https://example.com/one"))
|
/// .add_instrument(iri!("https://example.com/one"))
|
||||||
/// .add_instrument(uri!("https://example.com/two"));
|
/// .add_instrument(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -387,9 +386,9 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
/// # question.set_instrument(uri!("https://example.com"));
|
/// # question.set_instrument(iri!("https://example.com"));
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -410,8 +409,7 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
|
||||||
/// Documentation for the fields related to these methods can be found on the
|
/// Documentation for the fields related to these methods can be found on the
|
||||||
/// `ActorAndObject` struct
|
/// `ActorAndObject` struct
|
||||||
pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
||||||
/// Fetch the actor for the current activity, erroring if the actor's domain does not match the
|
/// Fetch the actor for the current activity
|
||||||
/// ID's domain
|
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, activity::Create};
|
/// # use activitystreams::{context, activity::Create};
|
||||||
|
@ -422,34 +420,7 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
||||||
/// let actor_ref = create.actor();
|
/// let actor_ref = create.actor();
|
||||||
/// println!("{:?}", actor_ref);
|
/// println!("{:?}", actor_ref);
|
||||||
/// ```
|
/// ```
|
||||||
fn actor<'a, Kind>(&'a self) -> Result<&OneOrMany<AnyBase>, DomainError>
|
fn actor(&self) -> &OneOrMany<AnyBase> {
|
||||||
where
|
|
||||||
Self: BaseExt<Kind>,
|
|
||||||
Kind: 'a,
|
|
||||||
{
|
|
||||||
let unchecked = self.actor_unchecked();
|
|
||||||
|
|
||||||
if unchecked.as_single_id().and_then(|id| id.domain())
|
|
||||||
!= self.id_unchecked().and_then(|id| id.domain())
|
|
||||||
{
|
|
||||||
return Err(DomainError);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(unchecked)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch the actor for the current activity
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # use activitystreams::{context, activity::Create};
|
|
||||||
/// # let mut create = Create::new(context(), context());
|
|
||||||
/// #
|
|
||||||
/// use activitystreams::prelude::*;
|
|
||||||
///
|
|
||||||
/// let actor_ref = create.actor_unchecked();
|
|
||||||
/// println!("{:?}", actor_ref);
|
|
||||||
/// ```
|
|
||||||
fn actor_unchecked(&self) -> &OneOrMany<AnyBase> {
|
|
||||||
self.actor_field_ref()
|
self.actor_field_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,18 +428,18 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{context, activity::Create, uri};
|
/// # use activitystreams::{context, activity::Create, iri};
|
||||||
/// # let mut create = Create::new(context(), context());
|
/// # let mut create = Create::new(context(), context());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// create.set_actor(uri!("https://example.com"));
|
/// create.set_actor(iri!("https://example.com"));
|
||||||
///
|
///
|
||||||
/// assert!(create.actor_is(&uri!("https://example.com")));
|
/// assert!(create.actor_is(&iri!("https://example.com")));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn actor_is(&self, id: &Url) -> bool {
|
fn actor_is(&self, id: &IriString) -> bool {
|
||||||
self.actor_unchecked().is_single_id(id)
|
self.actor().is_single_id(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the actor for the current activity
|
/// Set the actor for the current activity
|
||||||
|
@ -478,10 +449,10 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Create, uri};
|
/// # use activitystreams::{context, activity::Create, iri};
|
||||||
/// # let mut create = Create::new(context(), context());
|
/// # let mut create = Create::new(context(), context());
|
||||||
///
|
///
|
||||||
/// create.set_actor(uri!("https://example.com"));
|
/// create.set_actor(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -500,12 +471,12 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Create, uri};
|
/// # use activitystreams::{context, activity::Create, iri};
|
||||||
/// # let mut create = Create::new(context(), context());
|
/// # let mut create = Create::new(context(), context());
|
||||||
///
|
///
|
||||||
/// create.set_many_actors(vec![
|
/// create.set_many_actors(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -527,12 +498,12 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Create, uri};
|
/// # use activitystreams::{context, activity::Create, iri};
|
||||||
/// # let mut create = Create::new(context(), context());
|
/// # let mut create = Create::new(context(), context());
|
||||||
///
|
///
|
||||||
/// create
|
/// create
|
||||||
/// .add_actor(uri!("https://example.com/one"))
|
/// .add_actor(iri!("https://example.com/one"))
|
||||||
/// .add_actor(uri!("https://example.com/two"));
|
/// .add_actor(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -563,17 +534,17 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{context, activity::Create, uri};
|
/// # use activitystreams::{context, activity::Create, iri};
|
||||||
/// # let mut create = Create::new(context(), context());
|
/// # let mut create = Create::new(context(), context());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// create.set_object(uri!("https://example.com"));
|
/// create.set_object(iri!("https://example.com"));
|
||||||
///
|
///
|
||||||
/// assert!(create.object_is(&uri!("https://example.com")));
|
/// assert!(create.object_is(&iri!("https://example.com")));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn object_is(&self, id: &Url) -> bool {
|
fn object_is(&self, id: &IriString) -> bool {
|
||||||
self.object().is_single_id(id)
|
self.object().is_single_id(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,10 +555,10 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Create, uri};
|
/// # use activitystreams::{context, activity::Create, iri};
|
||||||
/// # let mut create = Create::new(context(), context());
|
/// # let mut create = Create::new(context(), context());
|
||||||
///
|
///
|
||||||
/// create.set_object(uri!("https://example.com"));
|
/// create.set_object(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -606,12 +577,12 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Create, uri};
|
/// # use activitystreams::{context, activity::Create, iri};
|
||||||
/// # let mut create = Create::new(context(), context());
|
/// # let mut create = Create::new(context(), context());
|
||||||
///
|
///
|
||||||
/// create.set_many_objects(vec![
|
/// create.set_many_objects(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -633,12 +604,12 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Create, uri};
|
/// # use activitystreams::{context, activity::Create, iri};
|
||||||
/// # let mut create = Create::new(context(), context());
|
/// # let mut create = Create::new(context(), context());
|
||||||
///
|
///
|
||||||
/// create
|
/// create
|
||||||
/// .add_object(uri!("https://example.com/one"))
|
/// .add_object(iri!("https://example.com/one"))
|
||||||
/// .add_object(uri!("https://example.com/two"));
|
/// .add_object(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -677,10 +648,10 @@ pub trait TargetRefExt: TargetRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Invite, uri};
|
/// # use activitystreams::{context, activity::Invite, iri};
|
||||||
/// # let mut invite = Invite::new(context(), context(), context());
|
/// # let mut invite = Invite::new(context(), context(), context());
|
||||||
///
|
///
|
||||||
/// invite.set_target(uri!("https://example.com"));
|
/// invite.set_target(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -699,12 +670,12 @@ pub trait TargetRefExt: TargetRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Invite, uri};
|
/// # use activitystreams::{context, activity::Invite, iri};
|
||||||
/// # let mut invite = Invite::new(context(), context(), context());
|
/// # let mut invite = Invite::new(context(), context(), context());
|
||||||
///
|
///
|
||||||
/// invite.set_many_targets(vec![
|
/// invite.set_many_targets(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -726,12 +697,12 @@ pub trait TargetRefExt: TargetRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Invite, uri};
|
/// # use activitystreams::{context, activity::Invite, iri};
|
||||||
/// # let mut invite = Invite::new(context(), context(), context());
|
/// # let mut invite = Invite::new(context(), context(), context());
|
||||||
///
|
///
|
||||||
/// invite
|
/// invite
|
||||||
/// .add_target(uri!("https://example.com/one"))
|
/// .add_target(iri!("https://example.com/one"))
|
||||||
/// .add_target(uri!("https://example.com/two"));
|
/// .add_target(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -770,10 +741,10 @@ pub trait OriginRefExt: OriginRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Arrive, uri};
|
/// # use activitystreams::{context, activity::Arrive, iri};
|
||||||
/// # let mut arrive = Arrive::new(context(), context());
|
/// # let mut arrive = Arrive::new(context(), context());
|
||||||
///
|
///
|
||||||
/// arrive.set_origin(uri!("https://example.com"));
|
/// arrive.set_origin(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -792,12 +763,12 @@ pub trait OriginRefExt: OriginRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Arrive, uri};
|
/// # use activitystreams::{context, activity::Arrive, iri};
|
||||||
/// # let mut arrive = Arrive::new(context(), context());
|
/// # let mut arrive = Arrive::new(context(), context());
|
||||||
///
|
///
|
||||||
/// arrive.set_many_origins(vec![
|
/// arrive.set_many_origins(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -819,12 +790,12 @@ pub trait OriginRefExt: OriginRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Arrive, uri};
|
/// # use activitystreams::{context, activity::Arrive, iri};
|
||||||
/// # let mut arrive = Arrive::new(context(), context());
|
/// # let mut arrive = Arrive::new(context(), context());
|
||||||
///
|
///
|
||||||
/// arrive
|
/// arrive
|
||||||
/// .add_origin(uri!("https://example.com/one"))
|
/// .add_origin(iri!("https://example.com/one"))
|
||||||
/// .add_origin(uri!("https://example.com/two"));
|
/// .add_origin(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -865,10 +836,10 @@ pub trait OptTargetRefExt: OptTargetRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Announce, uri};
|
/// # use activitystreams::{context, activity::Announce, iri};
|
||||||
/// # let mut announce = Announce::new(context(), context());
|
/// # let mut announce = Announce::new(context(), context());
|
||||||
///
|
///
|
||||||
/// announce.set_target(uri!("https://example.com"));
|
/// announce.set_target(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -887,12 +858,12 @@ pub trait OptTargetRefExt: OptTargetRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Announce, uri};
|
/// # use activitystreams::{context, activity::Announce, iri};
|
||||||
/// # let mut announce = Announce::new(context(), context());
|
/// # let mut announce = Announce::new(context(), context());
|
||||||
///
|
///
|
||||||
/// announce.set_many_targets(vec![
|
/// announce.set_many_targets(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -914,12 +885,12 @@ pub trait OptTargetRefExt: OptTargetRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Announce, uri};
|
/// # use activitystreams::{context, activity::Announce, iri};
|
||||||
/// # let mut announce = Announce::new(context(), context());
|
/// # let mut announce = Announce::new(context(), context());
|
||||||
///
|
///
|
||||||
/// announce
|
/// announce
|
||||||
/// .add_target(uri!("https://example.com/one"))
|
/// .add_target(iri!("https://example.com/one"))
|
||||||
/// .add_target(uri!("https://example.com/two"));
|
/// .add_target(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1011,10 +982,10 @@ pub trait OptOriginRefExt: OptOriginRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Delete, uri};
|
/// # use activitystreams::{context, activity::Delete, iri};
|
||||||
/// # let mut delete = Delete::new(context(), context());
|
/// # let mut delete = Delete::new(context(), context());
|
||||||
///
|
///
|
||||||
/// delete.set_origin(uri!("https://example.com"));
|
/// delete.set_origin(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1033,12 +1004,12 @@ pub trait OptOriginRefExt: OptOriginRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Delete, uri};
|
/// # use activitystreams::{context, activity::Delete, iri};
|
||||||
/// # let mut delete = Delete::new(context(), context());
|
/// # let mut delete = Delete::new(context(), context());
|
||||||
///
|
///
|
||||||
/// delete.set_many_origins(vec![
|
/// delete.set_many_origins(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -1060,12 +1031,12 @@ pub trait OptOriginRefExt: OptOriginRef {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, activity::Delete, uri};
|
/// # use activitystreams::{context, activity::Delete, iri};
|
||||||
/// # let mut delete = Delete::new(context(), context());
|
/// # let mut delete = Delete::new(context(), context());
|
||||||
///
|
///
|
||||||
/// delete
|
/// delete
|
||||||
/// .add_origin(uri!("https://example.com/one"))
|
/// .add_origin(iri!("https://example.com/one"))
|
||||||
/// .add_origin(uri!("https://example.com/two"));
|
/// .add_origin(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1153,10 +1124,10 @@ pub trait QuestionExt: AsQuestion {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question.set_one_of(uri!("https://example.com"));
|
/// question.set_one_of(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1175,12 +1146,12 @@ pub trait QuestionExt: AsQuestion {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question.set_many_one_ofs(vec![
|
/// question.set_many_one_ofs(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -1202,12 +1173,12 @@ pub trait QuestionExt: AsQuestion {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question
|
/// question
|
||||||
/// .add_one_of(uri!("https://example.com/one"))
|
/// .add_one_of(iri!("https://example.com/one"))
|
||||||
/// .add_one_of(uri!("https://example.com/two"));
|
/// .add_one_of(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1246,9 +1217,9 @@ pub trait QuestionExt: AsQuestion {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
/// # question.set_one_of(uri!("https://example.com"));
|
/// # question.set_one_of(iri!("https://example.com"));
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -1286,10 +1257,10 @@ pub trait QuestionExt: AsQuestion {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question.set_any_of(uri!("https://example.com"));
|
/// question.set_any_of(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1308,12 +1279,12 @@ pub trait QuestionExt: AsQuestion {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question.set_many_any_ofs(vec![
|
/// question.set_many_any_ofs(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -1335,12 +1306,12 @@ pub trait QuestionExt: AsQuestion {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
///
|
///
|
||||||
/// question
|
/// question
|
||||||
/// .add_any_of(uri!("https://example.com/one"))
|
/// .add_any_of(iri!("https://example.com/one"))
|
||||||
/// .add_any_of(uri!("https://example.com/two"));
|
/// .add_any_of(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1379,9 +1350,9 @@ pub trait QuestionExt: AsQuestion {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{activity::Question, uri};
|
/// # use activitystreams::{activity::Question, iri};
|
||||||
/// # let mut question = Question::new();
|
/// # let mut question = Question::new();
|
||||||
/// # question.set_any_of(uri!("https://example.com"));
|
/// # question.set_any_of(iri!("https://example.com"));
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -2341,6 +2312,7 @@ impl<Kind> ActorAndObjectOptOriginAndTarget<Kind> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
/// Deconstruct the ActorAndObjectOptOriginAndTarget into its parts
|
/// Deconstruct the ActorAndObjectOptOriginAndTarget into its parts
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -2530,6 +2502,7 @@ impl Travel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
/// Deconstruct the Travel into its parts
|
/// Deconstruct the Travel into its parts
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
|
511
src/actor.rs
511
src/actor.rs
|
@ -5,31 +5,30 @@
|
||||||
//! use activitystreams::{
|
//! use activitystreams::{
|
||||||
//! actor::{ApActor, Person},
|
//! actor::{ApActor, Person},
|
||||||
//! prelude::*,
|
//! prelude::*,
|
||||||
//! uri,
|
//! iri,
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
//! let mut person = ApActor::new(
|
//! let mut person = ApActor::new(
|
||||||
//! uri!("https://example.com/actor/inbox"),
|
//! iri!("https://example.com/actor/inbox"),
|
||||||
//! Person::new(),
|
//! Person::new(),
|
||||||
//! );
|
//! );
|
||||||
//!
|
//!
|
||||||
//! person
|
//! person
|
||||||
//! .set_outbox(uri!("https://example.com/actor/outbox"))
|
//! .set_outbox(iri!("https://example.com/actor/outbox"))
|
||||||
//! .set_following(uri!("https://example.com/actor/following"))
|
//! .set_following(iri!("https://example.com/actor/following"))
|
||||||
//! .set_followers(uri!("https://example.com/actor/followers"));
|
//! .set_followers(iri!("https://example.com/actor/followers"));
|
||||||
//! #
|
//! #
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
use crate::{
|
use crate::{
|
||||||
base::{AsBase, Base, BaseExt, Extends},
|
base::{AsBase, Base, Extends},
|
||||||
error::DomainError,
|
|
||||||
markers,
|
markers,
|
||||||
object::{ApObject, AsApObject, AsObject, Object},
|
object::{ApObject, AsApObject, AsObject, Object},
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
|
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
|
||||||
};
|
};
|
||||||
use url::Url;
|
use iri_string::types::IriString;
|
||||||
|
|
||||||
pub use activitystreams_kinds::actor as kind;
|
pub use activitystreams_kinds::actor as kind;
|
||||||
|
|
||||||
|
@ -52,36 +51,6 @@ pub trait AsApActor<Inner>: markers::Actor {
|
||||||
///
|
///
|
||||||
/// Documentation for the fields related to these methods can be found on the `ApActor` struct
|
/// Documentation for the fields related to these methods can be found on the `ApActor` struct
|
||||||
pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// Fetch the inbox for the current actor, erroring if the inbox's domain does not match the
|
|
||||||
/// ID's domain
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context};
|
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
|
||||||
/// # person.set_id(context());
|
|
||||||
/// use activitystreams::prelude::*;
|
|
||||||
///
|
|
||||||
/// let inbox = person.inbox()?;
|
|
||||||
/// println!("{:?}", inbox);
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
fn inbox<'a, Kind>(&'a self) -> Result<&'a Url, DomainError>
|
|
||||||
where
|
|
||||||
Self: BaseExt<Kind> + 'a,
|
|
||||||
Inner: 'a,
|
|
||||||
Kind: 'a,
|
|
||||||
{
|
|
||||||
let unchecked = self.inbox_unchecked();
|
|
||||||
|
|
||||||
if unchecked.domain() != self.id_unchecked().and_then(|id| id.domain()) {
|
|
||||||
return Err(DomainError);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(unchecked)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch the inbox for the current actor
|
/// Fetch the inbox for the current actor
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -89,9 +58,9 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// let inbox_ref = person.inbox_unchecked();
|
/// let inbox_ref = person.inbox();
|
||||||
/// ```
|
/// ```
|
||||||
fn inbox_unchecked<'a>(&'a self) -> &'a Url
|
fn inbox<'a>(&'a self) -> &'a IriString
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -106,9 +75,8 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// let inbox_mut = person.inbox_mut();
|
/// let inbox_mut = person.inbox_mut();
|
||||||
/// inbox_mut.set_path("/inbox");
|
|
||||||
/// ```
|
/// ```
|
||||||
fn inbox_mut<'a>(&'a mut self) -> &'a mut Url
|
fn inbox_mut<'a>(&'a mut self) -> &'a mut IriString
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -119,49 +87,19 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// person.set_inbox(uri!("https://example.com/inbox"));
|
/// person.set_inbox(iri!("https://example.com/inbox"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn set_inbox(&mut self, inbox: Url) -> &mut Self {
|
fn set_inbox(&mut self, inbox: IriString) -> &mut Self {
|
||||||
self.ap_actor_mut().inbox = inbox;
|
self.ap_actor_mut().inbox = inbox;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the outbox for the current user, erroring if the oubox's domain does not match the
|
|
||||||
/// ID's domain
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context};
|
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
|
||||||
/// use activitystreams::prelude::*;
|
|
||||||
///
|
|
||||||
/// let outbox_ref = person.outbox()?;
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
fn outbox<'a, Kind>(&'a self) -> Result<Option<&'a Url>, DomainError>
|
|
||||||
where
|
|
||||||
Self: BaseExt<Kind>,
|
|
||||||
Inner: 'a,
|
|
||||||
Kind: 'a,
|
|
||||||
{
|
|
||||||
if let Some(unchecked) = self.outbox_unchecked() {
|
|
||||||
if unchecked.domain() != self.id_unchecked().and_then(|id| id.domain()) {
|
|
||||||
return Err(DomainError);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Some(unchecked));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch the outbox for the current actor
|
/// Fetch the outbox for the current actor
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -169,9 +107,9 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// let outbox_ref = person.outbox_unchecked();
|
/// let outbox_ref = person.outbox();
|
||||||
/// ```
|
/// ```
|
||||||
fn outbox_unchecked<'a>(&'a self) -> Option<&'a Url>
|
fn outbox<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -186,11 +124,10 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(outbox) = person.outbox_mut() {
|
/// if let Some(outbox) = person.outbox_mut() {
|
||||||
/// outbox.set_path("/outbox");
|
|
||||||
/// println!("{:?}", outbox);
|
/// println!("{:?}", outbox);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn outbox_mut<'a>(&'a mut self) -> Option<&'a mut Url>
|
fn outbox_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -201,15 +138,15 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// person.set_outbox(uri!("https://example.com/outbox"));
|
/// person.set_outbox(iri!("https://example.com/outbox"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn set_outbox(&mut self, outbox: Url) -> &mut Self {
|
fn set_outbox(&mut self, outbox: IriString) -> &mut Self {
|
||||||
self.ap_actor_mut().outbox = Some(outbox);
|
self.ap_actor_mut().outbox = Some(outbox);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -225,7 +162,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// println!("{:?}", outbox);
|
/// println!("{:?}", outbox);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn take_outbox(&mut self) -> Option<Url> {
|
fn take_outbox(&mut self) -> Option<IriString> {
|
||||||
self.ap_actor_mut().outbox.take()
|
self.ap_actor_mut().outbox.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,14 +170,14 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// # person.set_outbox(uri!("https://example.com/outbox"));
|
/// # person.set_outbox(iri!("https://example.com/outbox"));
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// assert!(person.outbox_unchecked().is_some());
|
/// assert!(person.outbox().is_some());
|
||||||
/// person.delete_outbox();
|
/// person.delete_outbox();
|
||||||
/// assert!(person.outbox_unchecked().is_none());
|
/// assert!(person.outbox().is_none());
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -249,38 +186,6 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the following link for the current user, erroring if the following link's domain does
|
|
||||||
/// not match the ID's domain
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context};
|
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
|
||||||
/// use activitystreams::prelude::*;
|
|
||||||
///
|
|
||||||
/// if let Some(following) = person.following()? {
|
|
||||||
/// println!("{:?}", following);
|
|
||||||
/// }
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
fn following<'a, Kind>(&'a self) -> Result<Option<&'a Url>, DomainError>
|
|
||||||
where
|
|
||||||
Self: BaseExt<Kind>,
|
|
||||||
Inner: 'a,
|
|
||||||
Kind: 'a,
|
|
||||||
{
|
|
||||||
if let Some(unchecked) = self.following_unchecked() {
|
|
||||||
if unchecked.domain() != self.id_unchecked().and_then(|id| id.domain()) {
|
|
||||||
return Err(DomainError);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Some(unchecked));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch the following link for the current actor
|
/// Fetch the following link for the current actor
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -288,11 +193,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(following) = person.following_unchecked() {
|
/// if let Some(following) = person.following() {
|
||||||
/// println!("{:?}", following);
|
/// println!("{:?}", following);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn following_unchecked<'a>(&'a self) -> Option<&'a Url>
|
fn following<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -307,11 +212,10 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(following) = person.following_mut() {
|
/// if let Some(following) = person.following_mut() {
|
||||||
/// following.set_path("/following");
|
|
||||||
/// println!("{:?}", following);
|
/// println!("{:?}", following);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn following_mut<'a>(&'a mut self) -> Option<&'a mut Url>
|
fn following_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -322,15 +226,15 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// person.set_following(uri!("https://example.com/following"));
|
/// person.set_following(iri!("https://example.com/following"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn set_following(&mut self, following: Url) -> &mut Self {
|
fn set_following(&mut self, following: IriString) -> &mut Self {
|
||||||
self.ap_actor_mut().following = Some(following);
|
self.ap_actor_mut().following = Some(following);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -346,7 +250,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// println!("{:?}", following);
|
/// println!("{:?}", following);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn take_following(&mut self) -> Option<Url> {
|
fn take_following(&mut self) -> Option<IriString> {
|
||||||
self.ap_actor_mut().following.take()
|
self.ap_actor_mut().following.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,14 +258,14 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// # person.set_following(uri!("https://example.com/following"));
|
/// # person.set_following(iri!("https://example.com/following"));
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// assert!(person.following_unchecked().is_some());
|
/// assert!(person.following().is_some());
|
||||||
/// person.delete_following();
|
/// person.delete_following();
|
||||||
/// assert!(person.following_unchecked().is_none());
|
/// assert!(person.following().is_none());
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -370,38 +274,6 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the followers link for the current actor, erroring if the followers link's domain
|
|
||||||
/// does not match the ID's domain
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context};
|
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
|
||||||
/// use activitystreams::prelude::*;
|
|
||||||
///
|
|
||||||
/// if let Some(followers) = person.followers()? {
|
|
||||||
/// println!("{:?}", followers);
|
|
||||||
/// }
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
fn followers<'a, Kind>(&'a self) -> Result<Option<&'a Url>, DomainError>
|
|
||||||
where
|
|
||||||
Self: BaseExt<Kind>,
|
|
||||||
Inner: 'a,
|
|
||||||
Kind: 'a,
|
|
||||||
{
|
|
||||||
if let Some(unchecked) = self.followers_unchecked() {
|
|
||||||
if unchecked.domain() != self.id_unchecked().and_then(|id| id.domain()) {
|
|
||||||
return Err(DomainError);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Some(unchecked));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch the followers link for the current actor
|
/// Fetch the followers link for the current actor
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -409,11 +281,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(followers) = person.followers_unchecked() {
|
/// if let Some(followers) = person.followers() {
|
||||||
/// println!("{:?}", followers);
|
/// println!("{:?}", followers);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn followers_unchecked<'a>(&'a self) -> Option<&'a Url>
|
fn followers<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -428,11 +300,10 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(followers) = person.followers_mut() {
|
/// if let Some(followers) = person.followers_mut() {
|
||||||
/// followers.set_path("/followers");
|
|
||||||
/// println!("{:?}", followers);
|
/// println!("{:?}", followers);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn followers_mut<'a>(&'a mut self) -> Option<&'a mut Url>
|
fn followers_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -443,15 +314,15 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// person.set_followers(uri!("https://example.com/followers"));
|
/// person.set_followers(iri!("https://example.com/followers"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn set_followers(&mut self, followers: Url) -> &mut Self {
|
fn set_followers(&mut self, followers: IriString) -> &mut Self {
|
||||||
self.ap_actor_mut().followers = Some(followers);
|
self.ap_actor_mut().followers = Some(followers);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -467,7 +338,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// println!("{:?}", followers);
|
/// println!("{:?}", followers);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn take_followers(&mut self) -> Option<Url> {
|
fn take_followers(&mut self) -> Option<IriString> {
|
||||||
self.ap_actor_mut().followers.take()
|
self.ap_actor_mut().followers.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,14 +346,14 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// # person.set_followers(uri!("https://example.com/followers"));
|
/// # person.set_followers(iri!("https://example.com/followers"));
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// assert!(person.followers_unchecked().is_some());
|
/// assert!(person.followers().is_some());
|
||||||
/// person.delete_followers();
|
/// person.delete_followers();
|
||||||
/// assert!(person.followers_unchecked().is_none());
|
/// assert!(person.followers().is_none());
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -491,38 +362,6 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the liked link for the current actor, erroring if the liked link's domain does not
|
|
||||||
/// match the ID's domain
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context};
|
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
|
||||||
/// use activitystreams::prelude::*;
|
|
||||||
///
|
|
||||||
/// if let Some(liked) = person.liked()? {
|
|
||||||
/// println!("{:?}", liked);
|
|
||||||
/// }
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
fn liked<'a, Kind>(&'a self) -> Result<Option<&'a Url>, DomainError>
|
|
||||||
where
|
|
||||||
Self: BaseExt<Kind>,
|
|
||||||
Inner: 'a,
|
|
||||||
Kind: 'a,
|
|
||||||
{
|
|
||||||
if let Some(unchecked) = self.liked_unchecked() {
|
|
||||||
if unchecked.domain() != self.id_unchecked().and_then(|id| id.domain()) {
|
|
||||||
return Err(DomainError);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Some(unchecked));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch the liked link for the current actor
|
/// Fetch the liked link for the current actor
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -530,11 +369,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(liked) = person.liked_unchecked() {
|
/// if let Some(liked) = person.liked() {
|
||||||
/// println!("{:?}", liked);
|
/// println!("{:?}", liked);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn liked_unchecked<'a>(&'a self) -> Option<&'a Url>
|
fn liked<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -549,11 +388,10 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(liked) = person.liked_mut() {
|
/// if let Some(liked) = person.liked_mut() {
|
||||||
/// liked.set_path("/liked");
|
|
||||||
/// println!("{:?}", liked);
|
/// println!("{:?}", liked);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn liked_mut<'a>(&'a mut self) -> Option<&'a mut Url>
|
fn liked_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -564,15 +402,15 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// person.set_stream(uri!("https://example.com/liked"));
|
/// person.set_stream(iri!("https://example.com/liked"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn set_liked(&mut self, liked: Url) -> &mut Self {
|
fn set_liked(&mut self, liked: IriString) -> &mut Self {
|
||||||
self.ap_actor_mut().liked = Some(liked);
|
self.ap_actor_mut().liked = Some(liked);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -588,7 +426,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// println!("{:?}", liked);
|
/// println!("{:?}", liked);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn take_liked(&mut self) -> Option<Url> {
|
fn take_liked(&mut self) -> Option<IriString> {
|
||||||
self.ap_actor_mut().liked.take()
|
self.ap_actor_mut().liked.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,14 +434,14 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// # person.set_liked(uri!("https://example.com/liked"));
|
/// # person.set_liked(iri!("https://example.com/liked"));
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// assert!(person.liked_unchecked().is_some());
|
/// assert!(person.liked().is_some());
|
||||||
/// person.delete_liked();
|
/// person.delete_liked();
|
||||||
/// assert!(person.liked_unchecked().is_none());
|
/// assert!(person.liked().is_none());
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -612,50 +450,6 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the streams links for the current actor, erroring if the streams links's domains do
|
|
||||||
/// not match the ID's domains
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context};
|
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
|
||||||
/// # person.set_id(context()).add_stream(context()).add_stream(context());
|
|
||||||
/// use activitystreams::prelude::*;
|
|
||||||
///
|
|
||||||
/// if let Some(streams) = person.streams()? {
|
|
||||||
/// println!("{:?}", streams);
|
|
||||||
/// }
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
fn streams<'a, Kind>(&'a self) -> Result<Option<OneOrMany<&'a Url>>, DomainError>
|
|
||||||
where
|
|
||||||
Self: BaseExt<Kind>,
|
|
||||||
Inner: 'a,
|
|
||||||
Kind: 'a,
|
|
||||||
{
|
|
||||||
if let Some(unchecked) = self.streams_unchecked() {
|
|
||||||
let domain_opt = self.id_unchecked().and_then(|id| id.domain());
|
|
||||||
|
|
||||||
let one = unchecked
|
|
||||||
.as_one()
|
|
||||||
.map(|url| url.domain() == domain_opt)
|
|
||||||
.unwrap_or(false);
|
|
||||||
let many = unchecked
|
|
||||||
.as_many()
|
|
||||||
.map(|urls| urls.iter().all(|url| url.domain() == domain_opt))
|
|
||||||
.unwrap_or(false);
|
|
||||||
|
|
||||||
if !one && !many {
|
|
||||||
return Err(DomainError);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Some(unchecked));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch the streams links for the current actor
|
/// Fetch the streams links for the current actor
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -663,11 +457,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(streams) = person.streams_unchecked() {
|
/// if let Some(streams) = person.streams() {
|
||||||
/// println!("{:?}", streams);
|
/// println!("{:?}", streams);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn streams_unchecked<'a>(&'a self) -> Option<OneOrMany<&'a Url>>
|
fn streams<'a>(&'a self) -> Option<OneOrMany<&'a IriString>>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -682,16 +476,13 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(mut streams) = person.streams_mut() {
|
/// if let Some(mut streams) = person.streams_mut() {
|
||||||
/// streams.one_mut().map(|url| url.set_path("/streams"));
|
/// for url in streams.iter_mut() {
|
||||||
/// streams.many_mut().map(|urls| {
|
/// // whatever
|
||||||
/// for url in urls.iter_mut() {
|
|
||||||
/// url.set_path("/streams");
|
|
||||||
/// }
|
/// }
|
||||||
/// });
|
|
||||||
/// println!("{:?}", streams);
|
/// println!("{:?}", streams);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn streams_mut<'a>(&'a mut self) -> Option<OneOrMany<&'a mut Url>>
|
fn streams_mut<'a>(&'a mut self) -> Option<OneOrMany<&'a mut IriString>>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -702,15 +493,15 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// person.set_stream(uri!("https://example.com/streams"));
|
/// person.set_stream(iri!("https://example.com/streams"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn set_stream(&mut self, streams: Url) -> &mut Self {
|
fn set_stream(&mut self, streams: IriString) -> &mut Self {
|
||||||
self.ap_actor_mut().streams = Some(streams.into());
|
self.ap_actor_mut().streams = Some(streams.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -719,13 +510,13 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// person.set_many_streams(vec![
|
/// person.set_many_streams(vec![
|
||||||
/// uri!("https://example.com/streams1"),
|
/// iri!("https://example.com/streams1"),
|
||||||
/// uri!("https://example.com/streams2"),
|
/// iri!("https://example.com/streams2"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -733,9 +524,9 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
fn set_many_streams<I, U>(&mut self, items: I) -> &mut Self
|
fn set_many_streams<I, U>(&mut self, items: I) -> &mut Self
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = U>,
|
I: IntoIterator<Item = U>,
|
||||||
U: Into<Url>,
|
U: Into<IriString>,
|
||||||
{
|
{
|
||||||
let v: Vec<Url> = items.into_iter().map(|u| u.into()).collect();
|
let v: Vec<IriString> = 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
|
||||||
}
|
}
|
||||||
|
@ -744,17 +535,17 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// person
|
/// person
|
||||||
/// .add_stream(uri!("https://example.com/streams1"))
|
/// .add_stream(iri!("https://example.com/streams1"))
|
||||||
/// .add_stream(uri!("https://example.com/streams2"));
|
/// .add_stream(iri!("https://example.com/streams2"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn add_stream(&mut self, stream: Url) -> &mut Self {
|
fn add_stream(&mut self, stream: IriString) -> &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(stream);
|
v.add(stream);
|
||||||
|
@ -777,7 +568,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// println!("{:?}", streams);
|
/// println!("{:?}", streams);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn take_streams(&mut self) -> Option<OneOrMany<Url>> {
|
fn take_streams(&mut self) -> Option<OneOrMany<IriString>> {
|
||||||
self.ap_actor_mut().streams.take()
|
self.ap_actor_mut().streams.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -785,14 +576,14 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// # person.set_stream(uri!("https://example.com/streams"));
|
/// # person.set_stream(iri!("https://example.com/streams"));
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// assert!(person.streams_unchecked().is_some());
|
/// assert!(person.streams().is_some());
|
||||||
/// person.delete_streams();
|
/// person.delete_streams();
|
||||||
/// assert!(person.streams_unchecked().is_none());
|
/// assert!(person.streams().is_none());
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -871,71 +662,6 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the endpoints for the current actor, erroring if the Endpoints' domains do not
|
|
||||||
/// match the ID's domain
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
|
||||||
/// # use activitystreams::{actor::{ApActor, Endpoints, Person}, context};
|
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
|
||||||
/// # person.set_id(context()).set_endpoints(Endpoints {
|
|
||||||
/// # shared_inbox: Some(context()),
|
|
||||||
/// # ..Default::default()
|
|
||||||
/// # });
|
|
||||||
/// use activitystreams::prelude::*;
|
|
||||||
///
|
|
||||||
/// if let Some(endpoints) = person.endpoints()? {
|
|
||||||
/// println!("{:?}", endpoints);
|
|
||||||
/// }
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
fn endpoints<'a, Kind>(&'a self) -> Result<Option<Endpoints<&'a Url>>, DomainError>
|
|
||||||
where
|
|
||||||
Self: BaseExt<Kind>,
|
|
||||||
Inner: 'a,
|
|
||||||
Kind: 'a,
|
|
||||||
{
|
|
||||||
if let Some(endpoints) = self.endpoints_unchecked() {
|
|
||||||
let domain_opt = self.id_unchecked().and_then(|id| id.domain());
|
|
||||||
|
|
||||||
let mut any_failed = false;
|
|
||||||
|
|
||||||
any_failed |= endpoints
|
|
||||||
.proxy_url
|
|
||||||
.map(|u| u.domain() != domain_opt)
|
|
||||||
.unwrap_or(false);
|
|
||||||
any_failed |= endpoints
|
|
||||||
.oauth_authorization_endpoint
|
|
||||||
.map(|u| u.domain() != domain_opt)
|
|
||||||
.unwrap_or(false);
|
|
||||||
any_failed |= endpoints
|
|
||||||
.oauth_token_endpoint
|
|
||||||
.map(|u| u.domain() != domain_opt)
|
|
||||||
.unwrap_or(false);
|
|
||||||
any_failed |= endpoints
|
|
||||||
.provide_client_key
|
|
||||||
.map(|u| u.domain() != domain_opt)
|
|
||||||
.unwrap_or(false);
|
|
||||||
any_failed |= endpoints
|
|
||||||
.sign_client_key
|
|
||||||
.map(|u| u.domain() != domain_opt)
|
|
||||||
.unwrap_or(false);
|
|
||||||
any_failed |= endpoints
|
|
||||||
.shared_inbox
|
|
||||||
.map(|u| u.domain() != domain_opt)
|
|
||||||
.unwrap_or(false);
|
|
||||||
|
|
||||||
if any_failed {
|
|
||||||
return Err(DomainError);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Some(endpoints));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch the endpoints for the current actor
|
/// Fetch the endpoints for the current actor
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -943,11 +669,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(endpoints) = person.endpoints_unchecked() {
|
/// if let Some(endpoints) = person.endpoints() {
|
||||||
/// println!("{:?}", endpoints);
|
/// println!("{:?}", endpoints);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn endpoints_unchecked<'a>(&'a self) -> Option<Endpoints<&'a Url>>
|
fn endpoints<'a>(&'a self) -> Option<Endpoints<&'a IriString>>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -962,11 +688,13 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(mut endpoints) = person.endpoints_mut() {
|
/// if let Some(mut endpoints) = person.endpoints_mut() {
|
||||||
/// endpoints.shared_inbox.as_mut().map(|url| url.set_path("/inbox"));
|
/// if let Some(url) = endpoints.shared_inbox.as_mut() {
|
||||||
|
/// // whatever
|
||||||
|
/// }
|
||||||
/// println!("{:?}", endpoints);
|
/// println!("{:?}", endpoints);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn endpoints_mut<'a>(&'a mut self) -> Option<Endpoints<&'a mut Url>>
|
fn endpoints_mut<'a>(&'a mut self) -> Option<Endpoints<&'a mut IriString>>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Inner: 'a,
|
||||||
{
|
{
|
||||||
|
@ -977,18 +705,18 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{actor::{ApActor, Endpoints, Person}, context, uri};
|
/// # use activitystreams::{actor::{ApActor, Endpoints, Person}, context, iri};
|
||||||
/// # let mut person = ApActor::new(context(), Person::new());
|
/// # let mut person = ApActor::new(context(), Person::new());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// person.set_endpoints(Endpoints {
|
/// person.set_endpoints(Endpoints {
|
||||||
/// shared_inbox: Some(uri!("https://example.com/inbox")),
|
/// shared_inbox: Some(iri!("https://example.com/inbox")),
|
||||||
/// ..Default::default()
|
/// ..Default::default()
|
||||||
/// });
|
/// });
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn set_endpoints(&mut self, endpoints: Endpoints<Url>) -> &mut Self {
|
fn set_endpoints(&mut self, endpoints: Endpoints<IriString>) -> &mut Self {
|
||||||
self.ap_actor_mut().endpoints = Some(endpoints);
|
self.ap_actor_mut().endpoints = Some(endpoints);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -1004,7 +732,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// println!("{:?}", endpoints);
|
/// println!("{:?}", endpoints);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn take_endpoints(&mut self) -> Option<Endpoints<Url>> {
|
fn take_endpoints(&mut self) -> Option<Endpoints<IriString>> {
|
||||||
self.ap_actor_mut().endpoints.take()
|
self.ap_actor_mut().endpoints.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1016,9 +744,9 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// # person.set_endpoints(Default::default());
|
/// # person.set_endpoints(Default::default());
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// assert!(person.endpoints_unchecked().is_some());
|
/// assert!(person.endpoints().is_some());
|
||||||
/// person.delete_endpoints();
|
/// person.delete_endpoints();
|
||||||
/// assert!(person.endpoints_unchecked().is_none());
|
/// assert!(person.endpoints().is_none());
|
||||||
/// ```
|
/// ```
|
||||||
fn delete_endpoints(&mut self) -> &mut Self {
|
fn delete_endpoints(&mut self) -> &mut Self {
|
||||||
self.ap_actor_mut().endpoints = None;
|
self.ap_actor_mut().endpoints = None;
|
||||||
|
@ -1081,42 +809,42 @@ pub struct ApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// - Range: xsd:anyUri
|
/// - Range: xsd:anyUri
|
||||||
/// - Functional: true
|
/// - Functional: true
|
||||||
inbox: Url,
|
inbox: IriString,
|
||||||
|
|
||||||
/// 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<Url>,
|
outbox: Option<IriString>,
|
||||||
|
|
||||||
/// 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<Url>,
|
following: Option<IriString>,
|
||||||
|
|
||||||
/// 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<Url>,
|
followers: Option<IriString>,
|
||||||
|
|
||||||
/// 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<Url>,
|
liked: Option<IriString>,
|
||||||
|
|
||||||
/// 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<Url>>,
|
streams: Option<OneOrMany<IriString>>,
|
||||||
|
|
||||||
/// 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.
|
||||||
///
|
///
|
||||||
|
@ -1134,7 +862,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<Url>>,
|
endpoints: Option<Endpoints<IriString>>,
|
||||||
|
|
||||||
/// base fields and unparsed json ends up here
|
/// base fields and unparsed json ends up here
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
|
@ -1265,16 +993,16 @@ impl<Inner> ApActor<Inner> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::{actor::{ApActor, Person}, uri};
|
/// use activitystreams::{actor::{ApActor, Person}, iri};
|
||||||
///
|
///
|
||||||
/// let actor = ApActor::new(
|
/// let actor = ApActor::new(
|
||||||
/// uri!("https://example.com/inbox"),
|
/// iri!("https://example.com/inbox"),
|
||||||
/// Person::new(),
|
/// Person::new(),
|
||||||
/// );
|
/// );
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new(inbox: Url, inner: Inner) -> Self
|
pub fn new(inbox: IriString, inner: Inner) -> Self
|
||||||
where
|
where
|
||||||
Inner: markers::Actor,
|
Inner: markers::Actor,
|
||||||
{
|
{
|
||||||
|
@ -1291,13 +1019,14 @@ impl<Inner> ApActor<Inner> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
/// Deconstruct the ApActor into its parts
|
/// Deconstruct the ApActor into its parts
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::{actor::{ApActor, Person}, uri};
|
/// use activitystreams::{actor::{ApActor, Person}, iri};
|
||||||
///
|
///
|
||||||
/// let actor = ApActor::new(uri!("https://inbox.url"), Person::new());
|
/// let actor = ApActor::new(iri!("https://inbox.url"), Person::new());
|
||||||
///
|
///
|
||||||
/// let (
|
/// let (
|
||||||
/// inbox,
|
/// inbox,
|
||||||
|
@ -1316,14 +1045,14 @@ impl<Inner> ApActor<Inner> {
|
||||||
pub fn into_parts(
|
pub fn into_parts(
|
||||||
self,
|
self,
|
||||||
) -> (
|
) -> (
|
||||||
Url,
|
IriString,
|
||||||
Option<Url>,
|
Option<IriString>,
|
||||||
Option<Url>,
|
Option<IriString>,
|
||||||
Option<Url>,
|
Option<IriString>,
|
||||||
Option<Url>,
|
Option<IriString>,
|
||||||
Option<OneOrMany<Url>>,
|
Option<OneOrMany<IriString>>,
|
||||||
Option<String>,
|
Option<String>,
|
||||||
Option<Endpoints<Url>>,
|
Option<Endpoints<IriString>>,
|
||||||
Inner,
|
Inner,
|
||||||
) {
|
) {
|
||||||
(
|
(
|
||||||
|
@ -1400,12 +1129,12 @@ impl<T> Endpoints<T> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::{actor::Endpoints, uri};
|
/// use activitystreams::{actor::Endpoints, iri};
|
||||||
/// use url::Url;
|
/// use iri_string::types::IriString;
|
||||||
///
|
///
|
||||||
/// let uri = uri!("https://example.com");
|
/// let uri = iri!("https://example.com");
|
||||||
///
|
///
|
||||||
/// let endpoints: Endpoints<Url> = Endpoints {
|
/// let endpoints: Endpoints<IriString> = Endpoints {
|
||||||
/// shared_inbox: Some(uri.clone()),
|
/// shared_inbox: Some(uri.clone()),
|
||||||
/// ..Default::default()
|
/// ..Default::default()
|
||||||
/// };
|
/// };
|
||||||
|
@ -1441,17 +1170,17 @@ impl<T> Endpoints<T> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::{actor::Endpoints, uri};
|
/// use activitystreams::{actor::Endpoints, iri};
|
||||||
/// use url::Url;
|
/// use iri_string::types::IriString;
|
||||||
///
|
///
|
||||||
/// let endpoints: Endpoints<Url> = Endpoints {
|
/// let endpoints: Endpoints<IriString> = Endpoints {
|
||||||
/// shared_inbox: Some(uri!("https://example.com")),
|
/// shared_inbox: Some(iri!("https://example.com")),
|
||||||
/// ..Default::default()
|
/// ..Default::default()
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let endpoint_strings = endpoints.map(|u| u.to_string());
|
/// let endpoint_strings = endpoints.map(|u| u.to_string());
|
||||||
///
|
///
|
||||||
/// assert_eq!(endpoint_strings.shared_inbox, Some(String::from("https://example.com/")));
|
/// assert_eq!(endpoint_strings.shared_inbox, Some(String::from("https://example.com")));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
204
src/base.rs
204
src/base.rs
|
@ -8,12 +8,12 @@
|
||||||
//! object::Video,
|
//! object::Video,
|
||||||
//! prelude::*,
|
//! prelude::*,
|
||||||
//! security,
|
//! security,
|
||||||
//! uri,
|
//! iri,
|
||||||
//! };
|
//! };
|
||||||
//! let mut video = Video::new();
|
//! let mut video = Video::new();
|
||||||
//!
|
//!
|
||||||
//! video
|
//! video
|
||||||
//! .set_id(uri!("https://example.com"))
|
//! .set_id(iri!("https://example.com"))
|
||||||
//! .set_context(context())
|
//! .set_context(context())
|
||||||
//! .add_context(security())
|
//! .add_context(security())
|
||||||
//! .set_name("Hello");
|
//! .set_name("Hello");
|
||||||
|
@ -29,13 +29,12 @@
|
||||||
//! ```
|
//! ```
|
||||||
use crate::{
|
use crate::{
|
||||||
either::Either,
|
either::Either,
|
||||||
error::DomainError,
|
|
||||||
markers,
|
markers,
|
||||||
primitives::{AnyString, MimeMediaType, OneOrMany},
|
primitives::{AnyString, MimeMediaType, OneOrMany},
|
||||||
unparsed::{Unparsed, UnparsedMut},
|
unparsed::{Unparsed, UnparsedMut},
|
||||||
};
|
};
|
||||||
|
use iri_string::types::IriString;
|
||||||
use mime::Mime;
|
use mime::Mime;
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
/// Implements conversion between `Base<Kind>` and other ActivityStreams objects defined in this
|
/// Implements conversion between `Base<Kind>` and other ActivityStreams objects defined in this
|
||||||
/// crate
|
/// crate
|
||||||
|
@ -246,34 +245,6 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the id for the current object, checking it against the provided domain
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
|
||||||
/// # use activitystreams::{object::Video, uri};
|
|
||||||
/// # let mut video = Video::new();
|
|
||||||
/// # video.set_id(uri!("https://example.com"));
|
|
||||||
/// use activitystreams::prelude::*;
|
|
||||||
///
|
|
||||||
/// assert_eq!(video.id("example.com")?, Some(&uri!("https://example.com")));
|
|
||||||
/// # Ok(())
|
|
||||||
/// # }
|
|
||||||
/// ```
|
|
||||||
fn id<'a>(&'a self, domain: &str) -> Result<Option<&'a Url>, DomainError>
|
|
||||||
where
|
|
||||||
Kind: 'a,
|
|
||||||
{
|
|
||||||
if let Some(unchecked) = self.id_unchecked() {
|
|
||||||
if unchecked.domain() != Some(domain) {
|
|
||||||
return Err(DomainError);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(Some(unchecked));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch the id for the current object
|
/// Fetch the id for the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -282,11 +253,11 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(id) = video.id_unchecked() {
|
/// if let Some(id) = video.id() {
|
||||||
/// println!("{:?}", id);
|
/// println!("{:?}", id);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn id_unchecked<'a>(&'a self) -> Option<&'a Url>
|
fn id<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Kind: 'a,
|
Kind: 'a,
|
||||||
{
|
{
|
||||||
|
@ -302,11 +273,10 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(id) = video.id_mut() {
|
/// if let Some(id) = video.id_mut() {
|
||||||
/// id.set_path("/actor");
|
|
||||||
/// println!("{:?}", id);
|
/// println!("{:?}", id);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn id_mut<'a>(&'a mut self) -> Option<&'a mut Url>
|
fn id_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
||||||
where
|
where
|
||||||
Kind: 'a,
|
Kind: 'a,
|
||||||
{
|
{
|
||||||
|
@ -317,16 +287,16 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::{object::Video, prelude::*, uri};
|
/// use activitystreams::{object::Video, prelude::*, iri};
|
||||||
///
|
///
|
||||||
/// let video: Video = serde_json::from_str(r#"{"type":"Video","id":"https://example.com"}"#)?;
|
/// let video: Video = serde_json::from_str(r#"{"type":"Video","id":"https://example.com"}"#)?;
|
||||||
///
|
///
|
||||||
/// assert!(video.is_id(&uri!("https://example.com")));
|
/// assert!(video.is_id(&iri!("https://example.com")));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn is_id(&self, id: &Url) -> bool {
|
fn is_id(&self, id: &IriString) -> bool {
|
||||||
self.id_unchecked() == Some(id)
|
self.id() == Some(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the id for the current object
|
/// Set the id for the current object
|
||||||
|
@ -338,13 +308,13 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
/// # use activitystreams::object::Video;
|
/// # use activitystreams::object::Video;
|
||||||
/// # let mut video = Video::new();
|
/// # let mut video = Video::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, iri};
|
||||||
///
|
///
|
||||||
/// video.set_id(uri!("https://example.com"));
|
/// video.set_id(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn set_id(&mut self, id: Url) -> &mut Self {
|
fn set_id(&mut self, id: IriString) -> &mut Self {
|
||||||
self.base_mut().id = Some(id);
|
self.base_mut().id = Some(id);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -361,7 +331,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
/// println!("{:?}", id);
|
/// println!("{:?}", id);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn take_id(&mut self) -> Option<Url> {
|
fn take_id(&mut self) -> Option<IriString> {
|
||||||
self.base_mut().id.take()
|
self.base_mut().id.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,9 +344,9 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// assert!(video.id_unchecked().is_some());
|
/// assert!(video.id().is_some());
|
||||||
/// video.delete_id();
|
/// video.delete_id();
|
||||||
/// assert!(video.id_unchecked().is_none());
|
/// assert!(video.id().is_none());
|
||||||
/// ```
|
/// ```
|
||||||
fn delete_id(&mut self) -> &mut Self {
|
fn delete_id(&mut self) -> &mut Self {
|
||||||
self.base_mut().id = None;
|
self.base_mut().id = None;
|
||||||
|
@ -699,10 +669,10 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{object::Video, uri};
|
/// # use activitystreams::{object::Video, iri};
|
||||||
/// # let mut video = Video::new();
|
/// # let mut video = Video::new();
|
||||||
///
|
///
|
||||||
/// video.set_preview(uri!("https://example.com"));
|
/// video.set_preview(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -721,12 +691,12 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{object::Video, uri};
|
/// # use activitystreams::{object::Video, iri};
|
||||||
/// # let mut video = Video::new();
|
/// # let mut video = Video::new();
|
||||||
///
|
///
|
||||||
/// video.set_many_previews(vec![
|
/// video.set_many_previews(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -748,12 +718,12 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{object::Video, uri};
|
/// # use activitystreams::{object::Video, iri};
|
||||||
/// # let mut video = Video::new();
|
/// # let mut video = Video::new();
|
||||||
///
|
///
|
||||||
/// video
|
/// video
|
||||||
/// .add_preview(uri!("https://example.com/one"))
|
/// .add_preview(iri!("https://example.com/one"))
|
||||||
/// .add_preview(uri!("https://example.com/two"));
|
/// .add_preview(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -792,9 +762,9 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{object::Video, uri};
|
/// # use activitystreams::{object::Video, iri};
|
||||||
/// # let mut video = Video::new();
|
/// # let mut video = Video::new();
|
||||||
/// # video.set_preview(uri!("https://example.com"));
|
/// # video.set_preview(iri!("https://example.com"));
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -812,7 +782,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<Url, Box<Base<serde_json::Value>>>);
|
struct IdOrBase(Either<IriString, Box<Base<serde_json::Value>>>);
|
||||||
|
|
||||||
/// A type that can represent Any ActivityStreams type
|
/// A type that can represent Any ActivityStreams type
|
||||||
///
|
///
|
||||||
|
@ -858,7 +828,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<Url>,
|
id: Option<IriString>,
|
||||||
|
|
||||||
/// The `type` field
|
/// The `type` field
|
||||||
///
|
///
|
||||||
|
@ -1162,12 +1132,12 @@ impl AnyBase {
|
||||||
Ok(Base::retract(extended)?.into_generic()?.into())
|
Ok(Base::retract(extended)?.into_generic()?.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if this object is a Url
|
/// Check if this object is a IriString
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{base::AnyBase, uri};
|
/// # use activitystreams::{base::AnyBase, iri};
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
|
/// let any_base = AnyBase::from_xsd_any_uri(iri!("https://example.com"));
|
||||||
/// assert!(any_base.is_xsd_any_uri());
|
/// assert!(any_base.is_xsd_any_uri());
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -1217,9 +1187,9 @@ impl AnyBase {
|
||||||
/// #### Get the ID from the nested video
|
/// #### Get the ID from the nested video
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{object::Video, base::AnyBase, prelude::*, uri};
|
/// # use activitystreams::{object::Video, base::AnyBase, prelude::*, iri};
|
||||||
/// # let mut video = Video::new();
|
/// # let mut video = Video::new();
|
||||||
/// let id = uri!("https://example.com");
|
/// let id = iri!("https://example.com");
|
||||||
///
|
///
|
||||||
/// video.set_id(id.clone());
|
/// video.set_id(id.clone());
|
||||||
///
|
///
|
||||||
|
@ -1232,15 +1202,15 @@ impl AnyBase {
|
||||||
/// #### Get the ID from the AnyBase
|
/// #### Get the ID from the AnyBase
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{base::AnyBase, prelude::*, uri};
|
/// # use activitystreams::{base::AnyBase, prelude::*, iri};
|
||||||
/// let id = uri!("https://example.com");
|
/// let id = iri!("https://example.com");
|
||||||
///
|
///
|
||||||
/// let any_base = AnyBase::from_xsd_any_uri(id.clone());
|
/// let any_base = AnyBase::from_xsd_any_uri(id.clone());
|
||||||
/// assert!(any_base.id().unwrap() == &id);
|
/// assert!(any_base.id().unwrap() == &id);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn id(&self) -> Option<&Url> {
|
pub fn id(&self) -> Option<&IriString> {
|
||||||
self.as_xsd_any_uri()
|
self.as_xsd_any_uri()
|
||||||
.or_else(|| self.as_base().and_then(|base| base.id.as_ref()))
|
.or_else(|| self.as_base().and_then(|base| base.id.as_ref()))
|
||||||
}
|
}
|
||||||
|
@ -1250,19 +1220,19 @@ impl AnyBase {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{
|
/// # use activitystreams::{
|
||||||
/// # object::{kind::VideoType, Video}, base::AnyBase, prelude::*, uri
|
/// # object::{kind::VideoType, Video}, base::AnyBase, prelude::*, iri,
|
||||||
/// # };
|
/// # };
|
||||||
/// # let mut video = Video::new();
|
/// # let mut video = Video::new();
|
||||||
/// #
|
/// #
|
||||||
/// video.set_id(uri!("https://example.com"));
|
/// video.set_id(iri!("https://example.com"));
|
||||||
///
|
///
|
||||||
/// let any_base = AnyBase::from_extended(video)?;
|
/// let any_base = AnyBase::from_extended(video)?;
|
||||||
///
|
///
|
||||||
/// assert!(any_base.is_id(&uri!("https://example.com")));
|
/// assert!(any_base.is_id(&iri!("https://example.com")));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn is_id(&self, id: &Url) -> bool {
|
pub fn is_id(&self, id: &IriString) -> bool {
|
||||||
self.id() == Some(id)
|
self.id() == Some(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1340,20 +1310,20 @@ impl AnyBase {
|
||||||
self.kind_str() == Some(kind)
|
self.kind_str() == Some(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the object as a Url
|
/// Get the object as a IriString
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{base::AnyBase, uri};
|
/// # use activitystreams::{base::AnyBase, iri};
|
||||||
/// #
|
/// #
|
||||||
/// let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
|
/// let any_base = AnyBase::from_xsd_any_uri(iri!("https://example.com"));
|
||||||
///
|
///
|
||||||
/// assert!(any_base.as_xsd_any_uri().is_some());
|
/// assert!(any_base.as_xsd_any_uri().is_some());
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn as_xsd_any_uri(&self) -> Option<&Url> {
|
pub fn as_xsd_any_uri(&self) -> Option<&IriString> {
|
||||||
self.0.as_ref().left().and_then(|l| l.as_xsd_any_uri())
|
self.0.as_ref().left().and_then(|l| l.as_xsd_any_uri())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1388,20 +1358,20 @@ 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 Url from the Object
|
/// Take the IriString from the Object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{base::AnyBase, uri};
|
/// # use activitystreams::{base::AnyBase, iri};
|
||||||
/// #
|
/// #
|
||||||
/// let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
|
/// let any_base = AnyBase::from_xsd_any_uri(iri!("https://example.com"));
|
||||||
///
|
///
|
||||||
/// assert!(any_base.take_xsd_any_uri().is_some());
|
/// assert!(any_base.take_xsd_any_uri().is_some());
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn take_xsd_any_uri(self) -> Option<Url> {
|
pub fn take_xsd_any_uri(self) -> Option<IriString> {
|
||||||
self.0.left().and_then(|l| l.id())
|
self.0.left().and_then(|l| l.id())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1436,22 +1406,22 @@ impl AnyBase {
|
||||||
self.0.left().and_then(|l| l.base())
|
self.0.left().and_then(|l| l.base())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replace the object with the provided Url
|
/// Replace the object with the provided IriString
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{base::AnyBase, uri};
|
/// # use activitystreams::{base::AnyBase, iri};
|
||||||
/// #
|
/// #
|
||||||
/// let mut any_base = AnyBase::from_xsd_string("hi".into());
|
/// let mut any_base = AnyBase::from_xsd_string("hi".into());
|
||||||
///
|
///
|
||||||
/// any_base.set_xsd_any_uri(uri!("https://example.com"));
|
/// any_base.set_xsd_any_uri(iri!("https://example.com"));
|
||||||
///
|
///
|
||||||
/// assert!(any_base.take_xsd_any_uri().is_some());
|
/// assert!(any_base.take_xsd_any_uri().is_some());
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_xsd_any_uri(&mut self, id: Url) {
|
pub fn set_xsd_any_uri(&mut self, id: IriString) {
|
||||||
self.0 = Either::Left(IdOrBase::from_xsd_any_uri(id));
|
self.0 = Either::Left(IdOrBase::from_xsd_any_uri(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1459,9 +1429,9 @@ impl AnyBase {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{base::AnyBase, uri};
|
/// # use activitystreams::{base::AnyBase, iri};
|
||||||
/// #
|
/// #
|
||||||
/// let mut any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
|
/// let mut any_base = AnyBase::from_xsd_any_uri(iri!("https://example.com"));
|
||||||
///
|
///
|
||||||
/// any_base.set_xsd_string("hi");
|
/// any_base.set_xsd_string("hi");
|
||||||
///
|
///
|
||||||
|
@ -1497,16 +1467,16 @@ impl AnyBase {
|
||||||
self.0 = Either::Left(IdOrBase::from_base(base));
|
self.0 = Either::Left(IdOrBase::from_base(base));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an AnyBase from a Url
|
/// Create an AnyBase from a IriString
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::{base::AnyBase, uri};
|
/// use activitystreams::{base::AnyBase, iri};
|
||||||
/// let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
|
/// let any_base = AnyBase::from_xsd_any_uri(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn from_xsd_any_uri(id: Url) -> Self {
|
pub fn from_xsd_any_uri(id: IriString) -> Self {
|
||||||
AnyBase(Either::Left(IdOrBase::from_xsd_any_uri(id)))
|
AnyBase(Either::Left(IdOrBase::from_xsd_any_uri(id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1539,7 +1509,7 @@ impl AnyBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IdOrBase {
|
impl IdOrBase {
|
||||||
fn as_xsd_any_uri(&self) -> Option<&Url> {
|
fn as_xsd_any_uri(&self) -> Option<&IriString> {
|
||||||
self.0.as_ref().left()
|
self.0.as_ref().left()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1547,7 +1517,7 @@ impl IdOrBase {
|
||||||
self.0.as_ref().right().map(|b| b.as_ref())
|
self.0.as_ref().right().map(|b| b.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(self) -> Option<Url> {
|
fn id(self) -> Option<IriString> {
|
||||||
self.0.left()
|
self.0.left()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1555,7 +1525,7 @@ impl IdOrBase {
|
||||||
self.0.right().map(|b| *b)
|
self.0.right().map(|b| *b)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_xsd_any_uri(id: Url) -> Self {
|
fn from_xsd_any_uri(id: IriString) -> Self {
|
||||||
IdOrBase(Either::Left(id))
|
IdOrBase(Either::Left(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1569,9 +1539,9 @@ impl OneOrMany<AnyBase> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{base::{Base, BaseExt}, primitives::OneOrMany, uri};
|
/// # use activitystreams::{base::{Base, BaseExt}, primitives::OneOrMany, iri};
|
||||||
/// # let mut base = Base::<String>::new();
|
/// # let mut base = Base::<String>::new();
|
||||||
/// # let id = uri!("https://example.com");
|
/// # let id = iri!("https://example.com");
|
||||||
/// # base.set_id(id.clone());
|
/// # base.set_id(id.clone());
|
||||||
/// # let base = OneOrMany::from_base(base.into_generic()?.into());
|
/// # let base = OneOrMany::from_base(base.into_generic()?.into());
|
||||||
/// #
|
/// #
|
||||||
|
@ -1579,7 +1549,7 @@ impl OneOrMany<AnyBase> {
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn as_single_id(&self) -> Option<&Url> {
|
pub fn as_single_id(&self) -> Option<&IriString> {
|
||||||
self.as_one().and_then(|one| one.id())
|
self.as_one().and_then(|one| one.id())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1587,9 +1557,9 @@ impl OneOrMany<AnyBase> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{base::{Base, BaseExt}, primitives::OneOrMany, uri};
|
/// # use activitystreams::{base::{Base, BaseExt}, primitives::OneOrMany, iri};
|
||||||
/// # let mut base = Base::<String>::new();
|
/// # let mut base = Base::<String>::new();
|
||||||
/// # let id = uri!("https://example.com");
|
/// # let id = iri!("https://example.com");
|
||||||
/// # base.set_id(id.clone());
|
/// # base.set_id(id.clone());
|
||||||
/// # let base = OneOrMany::from_base(base.into_generic()?.into());
|
/// # let base = OneOrMany::from_base(base.into_generic()?.into());
|
||||||
/// #
|
/// #
|
||||||
|
@ -1597,7 +1567,7 @@ impl OneOrMany<AnyBase> {
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn is_single_id(&self, id: &Url) -> bool {
|
pub fn is_single_id(&self, id: &IriString) -> bool {
|
||||||
self.as_single_id() == Some(id)
|
self.as_single_id() == Some(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1655,20 +1625,20 @@ impl OneOrMany<AnyBase> {
|
||||||
self.as_single_kind_str() == Some(kind)
|
self.as_single_kind_str() == Some(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a single Url from the object, if that is what is contained
|
/// Get a single IriString from the object, if that is what is contained
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{primitives::OneOrMany, uri};
|
/// # use activitystreams::{primitives::OneOrMany, iri};
|
||||||
/// #
|
/// #
|
||||||
/// let one = OneOrMany::from_xsd_any_uri(uri!("https://example.com"));
|
/// let one = OneOrMany::from_xsd_any_uri(iri!("https://example.com"));
|
||||||
///
|
///
|
||||||
/// assert!(one.as_single_xsd_any_uri().is_some());
|
/// assert!(one.as_single_xsd_any_uri().is_some());
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn as_single_xsd_any_uri(&self) -> Option<&Url> {
|
pub fn as_single_xsd_any_uri(&self) -> Option<&IriString> {
|
||||||
self.as_one().and_then(|inner| inner.as_xsd_any_uri())
|
self.as_one().and_then(|inner| inner.as_xsd_any_uri())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1699,20 +1669,20 @@ impl OneOrMany<AnyBase> {
|
||||||
self.as_one().and_then(|inner| inner.as_base())
|
self.as_one().and_then(|inner| inner.as_base())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Take a single Url from the object, if that is what is contained
|
/// Take a single IriString from the object, if that is what is contained
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{primitives::OneOrMany, uri};
|
/// # use activitystreams::{primitives::OneOrMany, iri};
|
||||||
/// #
|
/// #
|
||||||
/// let one = OneOrMany::from_xsd_any_uri(uri!("https://example.com"));
|
/// let one = OneOrMany::from_xsd_any_uri(iri!("https://example.com"));
|
||||||
///
|
///
|
||||||
/// assert!(one.single_xsd_any_uri().is_some());
|
/// assert!(one.single_xsd_any_uri().is_some());
|
||||||
/// #
|
/// #
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn single_xsd_any_uri(self) -> Option<Url> {
|
pub fn single_xsd_any_uri(self) -> Option<IriString> {
|
||||||
self.one().and_then(|inner| inner.take_xsd_any_uri())
|
self.one().and_then(|inner| inner.take_xsd_any_uri())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1743,17 +1713,17 @@ impl OneOrMany<AnyBase> {
|
||||||
self.one().and_then(|inner| inner.take_base())
|
self.one().and_then(|inner| inner.take_base())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `OneOrMany<AnyBase>` from a Url
|
/// Create a `OneOrMany<AnyBase>` from a IriString
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::{primitives::OneOrMany, uri};
|
/// use activitystreams::{primitives::OneOrMany, iri};
|
||||||
///
|
///
|
||||||
/// let one = OneOrMany::from_xsd_any_uri(uri!("https://example.com"));
|
/// let one = OneOrMany::from_xsd_any_uri(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn from_xsd_any_uri(id: Url) -> Self {
|
pub fn from_xsd_any_uri(id: IriString) -> Self {
|
||||||
OneOrMany(Either::Left([AnyBase::from_xsd_any_uri(id)]))
|
OneOrMany(Either::Left([AnyBase::from_xsd_any_uri(id)]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1782,7 +1752,7 @@ impl OneOrMany<AnyBase> {
|
||||||
OneOrMany(Either::Left([AnyBase::from_base(base)]))
|
OneOrMany(Either::Left([AnyBase::from_base(base)]))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Overwrite the current object with a Url
|
/// Overwrite the current object with a IriString
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{base::Base, context, primitives::OneOrMany};
|
/// # use activitystreams::{base::Base, context, primitives::OneOrMany};
|
||||||
|
@ -1794,7 +1764,7 @@ impl OneOrMany<AnyBase> {
|
||||||
///
|
///
|
||||||
/// assert!(one.as_single_xsd_any_uri().is_some());
|
/// assert!(one.as_single_xsd_any_uri().is_some());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn set_single_xsd_any_uri(&mut self, id: Url) -> &mut Self {
|
pub fn set_single_xsd_any_uri(&mut self, id: IriString) -> &mut Self {
|
||||||
self.0 = Either::Left([AnyBase::from_xsd_any_uri(id)]);
|
self.0 = Either::Left([AnyBase::from_xsd_any_uri(id)]);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -1833,7 +1803,7 @@ impl OneOrMany<AnyBase> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append a Url to the current object
|
/// Append a IriString to the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use activitystreams::{base::AnyBase, context, primitives::OneOrMany, security};
|
/// use activitystreams::{base::AnyBase, context, primitives::OneOrMany, security};
|
||||||
|
@ -1843,7 +1813,7 @@ impl OneOrMany<AnyBase> {
|
||||||
/// many.add_xsd_any_uri(security())
|
/// many.add_xsd_any_uri(security())
|
||||||
/// .add_xsd_any_uri(context());
|
/// .add_xsd_any_uri(context());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn add_xsd_any_uri(&mut self, id: Url) -> &mut Self {
|
pub fn add_xsd_any_uri(&mut self, id: IriString) -> &mut Self {
|
||||||
self.add(AnyBase::from_xsd_any_uri(id))
|
self.add(AnyBase::from_xsd_any_uri(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1922,8 +1892,8 @@ impl From<Base<serde_json::Value>> for AnyBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Url> for AnyBase {
|
impl From<IriString> for AnyBase {
|
||||||
fn from(id: Url) -> Self {
|
fn from(id: IriString) -> Self {
|
||||||
Self::from_xsd_any_uri(id)
|
Self::from_xsd_any_uri(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1940,8 +1910,8 @@ impl From<Base<serde_json::Value>> for OneOrMany<AnyBase> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Url> for OneOrMany<AnyBase> {
|
impl From<IriString> for OneOrMany<AnyBase> {
|
||||||
fn from(xsd_any_uri: Url) -> Self {
|
fn from(xsd_any_uri: IriString) -> Self {
|
||||||
Self::from_xsd_any_uri(xsd_any_uri)
|
Self::from_xsd_any_uri(xsd_any_uri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,18 +6,18 @@
|
||||||
//! collection::OrderedCollection,
|
//! collection::OrderedCollection,
|
||||||
//! context,
|
//! context,
|
||||||
//! prelude::*,
|
//! prelude::*,
|
||||||
//! uri,
|
//! iri,
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
//! let mut collection = OrderedCollection::new();
|
//! let mut collection = OrderedCollection::new();
|
||||||
//!
|
//!
|
||||||
//! collection
|
//! collection
|
||||||
//! .set_item(uri!("https://example.com/notes/1234"))
|
//! .set_item(iri!("https://example.com/notes/1234"))
|
||||||
//! .set_total_items(1u64)
|
//! .set_total_items(1u64)
|
||||||
//! .set_current(uri!("https://example.com/notes/1234"))
|
//! .set_current(iri!("https://example.com/notes/1234"))
|
||||||
//! .set_first(uri!("https://example.com/notes/1234"))
|
//! .set_first(iri!("https://example.com/notes/1234"))
|
||||||
//! .set_last(uri!("https://example.com/notes/1234"))
|
//! .set_last(iri!("https://example.com/notes/1234"))
|
||||||
//! .set_id(uri!("https://example.com/collections/1234"))
|
//! .set_id(iri!("https://example.com/collections/1234"))
|
||||||
//! .set_context(context());
|
//! .set_context(context());
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
//! # }
|
//! # }
|
||||||
|
@ -92,10 +92,10 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{collection::UnorderedCollection, uri};
|
/// # use activitystreams::{collection::UnorderedCollection, iri};
|
||||||
/// # let mut collection = UnorderedCollection::new();
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
///
|
///
|
||||||
/// collection.set_item(uri!("https://example.com"));
|
/// collection.set_item(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -114,12 +114,12 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{collection::UnorderedCollection, uri};
|
/// # use activitystreams::{collection::UnorderedCollection, iri};
|
||||||
/// # let mut collection = UnorderedCollection::new();
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
///
|
///
|
||||||
/// collection.set_many_items(vec![
|
/// collection.set_many_items(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -141,12 +141,12 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{collection::UnorderedCollection, uri};
|
/// # use activitystreams::{collection::UnorderedCollection, iri};
|
||||||
/// # let mut collection = UnorderedCollection::new();
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
///
|
///
|
||||||
/// collection
|
/// collection
|
||||||
/// .add_item(uri!("https://example.com/one"))
|
/// .add_item(iri!("https://example.com/one"))
|
||||||
/// .add_item(uri!("https://example.com/two"));
|
/// .add_item(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -221,10 +221,10 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{collection::OrderedCollection, uri};
|
/// # use activitystreams::{collection::OrderedCollection, iri};
|
||||||
/// # let mut collection = OrderedCollection::new();
|
/// # let mut collection = OrderedCollection::new();
|
||||||
///
|
///
|
||||||
/// collection.set_ordered_item(uri!("https://example.com"));
|
/// collection.set_ordered_item(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -243,12 +243,12 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{collection::OrderedCollection, uri};
|
/// # use activitystreams::{collection::OrderedCollection, iri};
|
||||||
/// # let mut collection = OrderedCollection::new();
|
/// # let mut collection = OrderedCollection::new();
|
||||||
///
|
///
|
||||||
/// collection.set_many_ordered_items(vec![
|
/// collection.set_many_ordered_items(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// iri!("https://example.com/one"),
|
||||||
/// uri!("https://example.com/two"),
|
/// iri!("https://example.com/two"),
|
||||||
/// ]);
|
/// ]);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
|
@ -270,12 +270,12 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{collection::OrderedCollection, uri};
|
/// # use activitystreams::{collection::OrderedCollection, iri};
|
||||||
/// # let mut collection = OrderedCollection::new();
|
/// # let mut collection = OrderedCollection::new();
|
||||||
///
|
///
|
||||||
/// collection
|
/// collection
|
||||||
/// .add_ordered_item(uri!("https://example.com/one"))
|
/// .add_ordered_item(iri!("https://example.com/one"))
|
||||||
/// .add_ordered_item(uri!("https://example.com/two"));
|
/// .add_ordered_item(iri!("https://example.com/two"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -419,12 +419,12 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{collection::UnorderedCollection, uri};
|
/// # use activitystreams::{collection::UnorderedCollection, iri};
|
||||||
/// # let mut collection = UnorderedCollection::new();
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// collection.set_current(uri!("https://example.com"));
|
/// collection.set_current(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -498,9 +498,9 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// # use activitystreams::{collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new();
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, iri};
|
||||||
///
|
///
|
||||||
/// collection.set_first(uri!("https://example.com"));
|
/// collection.set_first(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -574,9 +574,9 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// # use activitystreams::{collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new();
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, iri};
|
||||||
///
|
///
|
||||||
/// collection.set_last(uri!("https://example.com"));
|
/// collection.set_last(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -658,9 +658,9 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new();
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, iri};
|
||||||
///
|
///
|
||||||
/// collection.set_part_of(uri!("https://example.com"));
|
/// collection.set_part_of(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -734,9 +734,9 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new();
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, iri};
|
||||||
///
|
///
|
||||||
/// collection.set_next(uri!("https://example.com"));
|
/// collection.set_next(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -810,9 +810,9 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new();
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, iri};
|
||||||
///
|
///
|
||||||
/// collection.set_prev(uri!("https://example.com"));
|
/// collection.set_prev(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
#[derive(Clone, Debug, thiserror::Error)]
|
|
||||||
#[error("URL did not match expected domain")]
|
|
||||||
pub struct DomainError;
|
|
51
src/lib.rs
51
src/lib.rs
|
@ -143,9 +143,9 @@
|
||||||
//!
|
//!
|
||||||
//! For fields with more specific bounds, like `id`,
|
//! For fields with more specific bounds, like `id`,
|
||||||
//! ```rust,ignore
|
//! ```rust,ignore
|
||||||
//! fn id(&self) -> Option<&Url>;
|
//! fn id(&self) -> Option<&IriString>;
|
||||||
//! fn set_id(&mut self, Url) -> &mut Self;
|
//! fn set_id(&mut self, IriString) -> &mut Self;
|
||||||
//! fn take_id(&self) -> Option<Url>;
|
//! fn take_id(&self) -> Option<IriString>;
|
||||||
//! fn delete_id(&mut self) -> &mut Self;
|
//! fn delete_id(&mut self) -> &mut Self;
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
@ -164,14 +164,14 @@
|
||||||
//! bound the function like so:
|
//! bound the function like so:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use activitystreams::{base::BaseExt, context, markers::Activity, uri};
|
//! use activitystreams::{base::BaseExt, context, markers::Activity, iri};
|
||||||
//!
|
//!
|
||||||
//! fn manipulator<T, Kind>(mut activity: T) -> Result<(), anyhow::Error>
|
//! fn manipulator<T, Kind>(mut activity: T) -> Result<(), anyhow::Error>
|
||||||
//! where
|
//! where
|
||||||
//! T: Activity + BaseExt<Kind>,
|
//! T: Activity + BaseExt<Kind>,
|
||||||
//! {
|
//! {
|
||||||
//! activity
|
//! activity
|
||||||
//! .set_id(uri!("https://example.com"))
|
//! .set_id(iri!("https://example.com"))
|
||||||
//! .set_context(context());
|
//! .set_context(context());
|
||||||
//! Ok(())
|
//! Ok(())
|
||||||
//! }
|
//! }
|
||||||
|
@ -205,21 +205,21 @@
|
||||||
//! context,
|
//! context,
|
||||||
//! object::{ApObject, Video},
|
//! object::{ApObject, Video},
|
||||||
//! prelude::*,
|
//! prelude::*,
|
||||||
//! uri,
|
//! iri,
|
||||||
//! };
|
//! };
|
||||||
//! use chrono::Duration;
|
//! use time::Duration;
|
||||||
//!
|
//!
|
||||||
//! fn main() -> Result<(), anyhow::Error> {
|
//! fn main() -> Result<(), anyhow::Error> {
|
||||||
//! let mut video = ApObject::new(Video::new());
|
//! let mut video = ApObject::new(Video::new());
|
||||||
//!
|
//!
|
||||||
//! video
|
//! video
|
||||||
//! .set_context(context())
|
//! .set_context(context())
|
||||||
//! .set_id(uri!("https://example.com/@example/lions"))
|
//! .set_id(iri!("https://example.com/@example/lions"))
|
||||||
//! .set_media_type("video/webm".parse()?)
|
//! .set_media_type("video/webm".parse()?)
|
||||||
//! .set_url(uri!("https://example.com/@example/lions/video.webm"))
|
//! .set_url(iri!("https://example.com/@example/lions/video.webm"))
|
||||||
//! .set_summary("A cool video")
|
//! .set_summary("A cool video")
|
||||||
//! .set_duration(Duration::minutes(4) + Duration::seconds(20))
|
//! .set_duration(Duration::minutes(4) + Duration::seconds(20))
|
||||||
//! .set_shares(uri!("https://example.com/@example/lions/video.webm#shares"));
|
//! .set_shares(iri!("https://example.com/@example/lions/video.webm#shares"));
|
||||||
//!
|
//!
|
||||||
//! println!("Video, {:#?}", video);
|
//! println!("Video, {:#?}", video);
|
||||||
//!
|
//!
|
||||||
|
@ -300,7 +300,6 @@ pub mod actor;
|
||||||
pub mod base;
|
pub mod base;
|
||||||
pub mod collection;
|
pub mod collection;
|
||||||
mod either;
|
mod either;
|
||||||
pub mod error;
|
|
||||||
pub mod link;
|
pub mod link;
|
||||||
mod macros;
|
mod macros;
|
||||||
pub mod markers;
|
pub mod markers;
|
||||||
|
@ -308,11 +307,13 @@ pub mod object;
|
||||||
pub mod primitives;
|
pub mod primitives;
|
||||||
pub mod unparsed;
|
pub mod unparsed;
|
||||||
|
|
||||||
pub extern crate chrono;
|
pub extern crate iri_string;
|
||||||
pub extern crate mime;
|
pub extern crate mime;
|
||||||
pub extern crate url;
|
pub extern crate time;
|
||||||
|
|
||||||
pub use activitystreams_kinds::{context, kind, public, security};
|
pub use activitystreams_kinds::{
|
||||||
|
context_iri as context, kind, public_iri as public, security_iri as security,
|
||||||
|
};
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
//! Extension traits that provide the majority of the helper methods of the crate
|
//! Extension traits that provide the majority of the helper methods of the crate
|
||||||
|
@ -327,38 +328,38 @@ pub mod prelude {
|
||||||
//! public,
|
//! public,
|
||||||
//! object::{ApObject, Image, Video},
|
//! object::{ApObject, Image, Video},
|
||||||
//! security,
|
//! security,
|
||||||
//! uri,
|
//! iri,
|
||||||
//! };
|
//! };
|
||||||
//! use chrono::Duration;
|
//! use time::Duration;
|
||||||
//!
|
//!
|
||||||
//! let mut person = ApActor::new(
|
//! let mut person = ApActor::new(
|
||||||
//! uri!("http://localhost:8080/inbox"),
|
//! iri!("http://localhost:8080/inbox"),
|
||||||
//! Person::new(),
|
//! Person::new(),
|
||||||
//! );
|
//! );
|
||||||
//! person
|
//! person
|
||||||
//! .set_outbox(uri!("http:/localhost:8080/outbox"))
|
//! .set_outbox(iri!("http:/localhost:8080/outbox"))
|
||||||
//! .set_name("Demo Account")
|
//! .set_name("Demo Account")
|
||||||
//! .set_preferred_username("demo")
|
//! .set_preferred_username("demo")
|
||||||
//! .set_id(uri!("https://localhost:8080/actor"))
|
//! .set_id(iri!("https://localhost:8080/actor"))
|
||||||
//! .set_url(uri!("https://localhost:8080/actor"));
|
//! .set_url(iri!("https://localhost:8080/actor"));
|
||||||
//!
|
//!
|
||||||
//! let mut preview = Image::new();
|
//! let mut preview = Image::new();
|
||||||
//!
|
//!
|
||||||
//! preview
|
//! preview
|
||||||
//! .set_url(uri!("https://localhost:8080/preview.png"))
|
//! .set_url(iri!("https://localhost:8080/preview.png"))
|
||||||
//! .set_media_type("image/png".parse()?)
|
//! .set_media_type("image/png".parse()?)
|
||||||
//! .set_id(uri!("https://localhostst:8080/preview.png"));
|
//! .set_id(iri!("https://localhostst:8080/preview.png"));
|
||||||
//!
|
//!
|
||||||
//! let mut video = ApObject::new(Video::new());
|
//! let mut video = ApObject::new(Video::new());
|
||||||
//!
|
//!
|
||||||
//! video
|
//! video
|
||||||
//! .set_id(uri!("http://localhost:8080/video.webm"))
|
//! .set_id(iri!("http://localhost:8080/video.webm"))
|
||||||
//! .set_url(uri!("http://localhost:8080/video.webm"))
|
//! .set_url(iri!("http://localhost:8080/video.webm"))
|
||||||
//! .set_media_type("video/webm".parse()?)
|
//! .set_media_type("video/webm".parse()?)
|
||||||
//! .set_summary("A cool video")
|
//! .set_summary("A cool video")
|
||||||
//! .set_preview(preview.into_any_base()?)
|
//! .set_preview(preview.into_any_base()?)
|
||||||
//! .set_duration(Duration::minutes(4) + Duration::seconds(20))
|
//! .set_duration(Duration::minutes(4) + Duration::seconds(20))
|
||||||
//! .set_shares(uri!("http://localhost:8080/video.webm#shares"));
|
//! .set_shares(iri!("http://localhost:8080/video.webm#shares"));
|
||||||
//!
|
//!
|
||||||
//! let mut activity = Create::new(
|
//! let mut activity = Create::new(
|
||||||
//! person.into_any_base()?,
|
//! person.into_any_base()?,
|
||||||
|
|
22
src/link.rs
22
src/link.rs
|
@ -6,13 +6,13 @@
|
||||||
//! link::Mention,
|
//! link::Mention,
|
||||||
//! object::Image,
|
//! object::Image,
|
||||||
//! prelude::*,
|
//! prelude::*,
|
||||||
//! uri,
|
//! iri,
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
//! let mut mention = Mention::new();
|
//! let mut mention = Mention::new();
|
||||||
//!
|
//!
|
||||||
//! mention
|
//! mention
|
||||||
//! .set_href(uri!("https://example.com"))
|
//! .set_href(iri!("https://example.com"))
|
||||||
//! .set_hreflang("en")
|
//! .set_hreflang("en")
|
||||||
//! .set_rel("link")
|
//! .set_rel("link")
|
||||||
//! .set_preview(Image::new().into_any_base()?);
|
//! .set_preview(Image::new().into_any_base()?);
|
||||||
|
@ -26,8 +26,8 @@ use crate::{
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
|
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
|
||||||
};
|
};
|
||||||
|
use iri_string::types::IriString;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
pub use activitystreams_kinds::link as kind;
|
pub use activitystreams_kinds::link as kind;
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
|
||||||
///
|
///
|
||||||
/// let mention_href = mention.href();
|
/// let mention_href = mention.href();
|
||||||
/// ```
|
/// ```
|
||||||
fn href<'a>(&'a self) -> Option<&'a Url>
|
fn href<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Kind: 'a,
|
Kind: 'a,
|
||||||
{
|
{
|
||||||
|
@ -73,16 +73,16 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{link::Mention, uri};
|
/// # use activitystreams::{link::Mention, iri};
|
||||||
/// # let mut mention = Mention::new();
|
/// # let mut mention = Mention::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// mention.set_href(uri!("https://example.com"));
|
/// mention.set_href(iri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn set_href(&mut self, href: Url) -> &mut Self {
|
fn set_href(&mut self, href: IriString) -> &mut Self {
|
||||||
self.link_mut().href = Some(href);
|
self.link_mut().href = Some(href);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
|
||||||
/// println!("{:?}", href);
|
/// println!("{:?}", href);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn take_href(&mut self) -> Option<Url> {
|
fn take_href(&mut self) -> Option<IriString> {
|
||||||
self.link_mut().href.take()
|
self.link_mut().href.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +107,9 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{link::Mention, uri};
|
/// # use activitystreams::{link::Mention, iri};
|
||||||
/// # let mut mention = Mention::new();
|
/// # let mut mention = Mention::new();
|
||||||
/// # mention.set_href(uri!("https://example.com"));
|
/// # mention.set_href(iri!("https://example.com"));
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -493,7 +493,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<Url>,
|
href: Option<IriString>,
|
||||||
|
|
||||||
/// Hints as to the language used by the target resource.
|
/// Hints as to the language used by the target resource.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,20 +1,58 @@
|
||||||
/// A macro to shorten the `string.parse::<Url>()?` calls inevitably made in downstream code
|
/// A macro to shorten the `string.parse::<Url>()?` calls inevitably made in downstream code
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use activitystreams::uri;
|
/// use activitystreams::iri;
|
||||||
///
|
///
|
||||||
/// fn fallible() -> Result<(), anyhow::Error> {
|
/// fn fallible() -> Result<(), anyhow::Error> {
|
||||||
/// let my_uri = uri!("https://example.com");
|
/// let my_iri = iri!("https://example.com");
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// # fn main() -> Result<(), anyhow::Error> { fallible() }
|
/// # fn main() -> Result<(), anyhow::Error> { fallible() }
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! uri {
|
macro_rules! iri {
|
||||||
( $x:expr ) => {{
|
( $x:expr ) => {{
|
||||||
use activitystreams::url::Url;
|
use activitystreams::iri_string::types::IriString;
|
||||||
|
|
||||||
$x.parse::<Url>()?
|
$x.parse::<IriString>()?
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A macro to parse IRI fragments
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// use activitystreams::fragment;
|
||||||
|
///
|
||||||
|
/// fn fallible() -> Result<(), anyhow::Error> {
|
||||||
|
/// let my_fragment = fragment!("main-key");
|
||||||
|
/// Ok(())
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! fragment {
|
||||||
|
( $x:expr ) => {{
|
||||||
|
use activitystreams::iri_string::types::IriFragmentString;
|
||||||
|
|
||||||
|
$x.parse::<IriFragmentString>()?
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A macro to parse Rfc3339 datetimes
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use activitystreams::datetime;
|
||||||
|
///
|
||||||
|
/// fn fallible() -> Result<(), anyhow::Error> {
|
||||||
|
/// let my_datetime = datetime!("2020-04-20T04:20:00Z");
|
||||||
|
/// Ok(())
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! datetime {
|
||||||
|
( $x:expr ) => {{
|
||||||
|
use activitystreams::time::{format_description::well_known::Rfc3339, OffsetDateTime};
|
||||||
|
|
||||||
|
OffsetDateTime::parse($x, &Rfc3339)?
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
521
src/object.rs
521
src/object.rs
File diff suppressed because it is too large
Load diff
|
@ -31,56 +31,56 @@
|
||||||
/// UTC, is represented as -05:00. If no time zone value is present, it is considered unknown; it
|
/// UTC, is represented as -05:00. If no time zone value is present, it is considered unknown; it
|
||||||
/// is not assumed to be UTC.
|
/// is not assumed to be UTC.
|
||||||
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct XsdDateTime(pub chrono::DateTime<chrono::FixedOffset>);
|
pub struct XsdDateTime(pub time::OffsetDateTime);
|
||||||
|
|
||||||
impl XsdDateTime {
|
impl XsdDateTime {
|
||||||
/// Create a XsdDateTime from a chrono::DateTime
|
/// Create a XsdDateTime from a time::OffsetDateTime
|
||||||
pub fn new(d: chrono::DateTime<chrono::FixedOffset>) -> Self {
|
pub fn new(d: time::OffsetDateTime) -> Self {
|
||||||
XsdDateTime(d)
|
XsdDateTime(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the chrono::DateTime from XsdDateTime
|
/// Extract the time::OffsetDateTime from XsdDateTime
|
||||||
pub fn into_inner(self) -> chrono::DateTime<chrono::FixedOffset> {
|
pub fn into_inner(self) -> time::OffsetDateTime {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Borrow the underlying `chrono::DateTime<chrono::FixedOffset>`
|
/// Borrow the underlying `time::OffsetDateTime`
|
||||||
pub fn as_datetime(&self) -> &chrono::DateTime<chrono::FixedOffset> {
|
pub fn as_datetime(&self) -> &time::OffsetDateTime {
|
||||||
self.as_ref()
|
self.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mutably borrow the underlying `chrono::DateTime<chrono::FixedOffset>`
|
/// Mutably borrow the underlying `time::OffsetDateTime`
|
||||||
pub fn as_datetime_mut(&mut self) -> &mut chrono::DateTime<chrono::FixedOffset> {
|
pub fn as_datetime_mut(&mut self) -> &mut time::OffsetDateTime {
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<chrono::DateTime<chrono::FixedOffset>> for XsdDateTime {
|
impl From<time::OffsetDateTime> for XsdDateTime {
|
||||||
fn from(d: chrono::DateTime<chrono::FixedOffset>) -> Self {
|
fn from(d: time::OffsetDateTime) -> Self {
|
||||||
XsdDateTime(d)
|
XsdDateTime(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<XsdDateTime> for chrono::DateTime<chrono::FixedOffset> {
|
impl From<XsdDateTime> for time::OffsetDateTime {
|
||||||
fn from(d: XsdDateTime) -> Self {
|
fn from(d: XsdDateTime) -> Self {
|
||||||
d.0
|
d.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRef<chrono::DateTime<chrono::FixedOffset>> for XsdDateTime {
|
impl AsRef<time::OffsetDateTime> for XsdDateTime {
|
||||||
fn as_ref(&self) -> &chrono::DateTime<chrono::FixedOffset> {
|
fn as_ref(&self) -> &time::OffsetDateTime {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsMut<chrono::DateTime<chrono::FixedOffset>> for XsdDateTime {
|
impl AsMut<time::OffsetDateTime> for XsdDateTime {
|
||||||
fn as_mut(&mut self) -> &mut chrono::DateTime<chrono::FixedOffset> {
|
fn as_mut(&mut self) -> &mut time::OffsetDateTime {
|
||||||
&mut self.0
|
&mut self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::TryFrom<String> for XsdDateTime {
|
impl std::convert::TryFrom<String> for XsdDateTime {
|
||||||
type Error = chrono::format::ParseError;
|
type Error = time::error::Parse;
|
||||||
|
|
||||||
fn try_from(s: String) -> Result<Self, Self::Error> {
|
fn try_from(s: String) -> Result<Self, Self::Error> {
|
||||||
s.parse()
|
s.parse()
|
||||||
|
@ -88,7 +88,7 @@ impl std::convert::TryFrom<String> for XsdDateTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::TryFrom<&str> for XsdDateTime {
|
impl std::convert::TryFrom<&str> for XsdDateTime {
|
||||||
type Error = chrono::format::ParseError;
|
type Error = time::error::Parse;
|
||||||
|
|
||||||
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
||||||
s.parse()
|
s.parse()
|
||||||
|
@ -96,7 +96,7 @@ impl std::convert::TryFrom<&str> for XsdDateTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::TryFrom<&mut str> for XsdDateTime {
|
impl std::convert::TryFrom<&mut str> for XsdDateTime {
|
||||||
type Error = chrono::format::ParseError;
|
type Error = time::error::Parse;
|
||||||
|
|
||||||
fn try_from(s: &mut str) -> Result<Self, Self::Error> {
|
fn try_from(s: &mut str) -> Result<Self, Self::Error> {
|
||||||
s.parse()
|
s.parse()
|
||||||
|
@ -104,16 +104,22 @@ impl std::convert::TryFrom<&mut str> for XsdDateTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for XsdDateTime {
|
impl std::str::FromStr for XsdDateTime {
|
||||||
type Err = chrono::format::ParseError;
|
type Err = time::error::Parse;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
Ok(XsdDateTime(chrono::DateTime::parse_from_rfc3339(s)?))
|
Ok(XsdDateTime(time::OffsetDateTime::parse(
|
||||||
|
s,
|
||||||
|
&time::format_description::well_known::Rfc3339,
|
||||||
|
)?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for XsdDateTime {
|
impl std::fmt::Display for XsdDateTime {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
let s = self.0.to_rfc3339();
|
let s = self
|
||||||
|
.0
|
||||||
|
.format(&time::format_description::well_known::Rfc3339)
|
||||||
|
.map_err(|_| std::fmt::Error)?;
|
||||||
std::fmt::Display::fmt(&s, f)
|
std::fmt::Display::fmt(&s, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
/// multiplying by 365. If this is an issue for your application, look into specifying days
|
/// multiplying by 365. If this is an issue for your application, look into specifying days
|
||||||
/// directly.
|
/// directly.
|
||||||
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct XsdDuration(pub chrono::Duration);
|
pub struct XsdDuration(pub time::Duration);
|
||||||
|
|
||||||
/// The error type produced when an XsdDuration cannot be parsed
|
/// The error type produced when an XsdDuration cannot be parsed
|
||||||
#[derive(Clone, Debug, thiserror::Error)]
|
#[derive(Clone, Debug, thiserror::Error)]
|
||||||
|
@ -50,47 +50,47 @@ pub struct XsdDuration(pub chrono::Duration);
|
||||||
pub struct XsdDurationError;
|
pub struct XsdDurationError;
|
||||||
|
|
||||||
impl XsdDuration {
|
impl XsdDuration {
|
||||||
/// Create a new XsdDuration from a chrono::Duration
|
/// Create a new XsdDuration from a time::Duration
|
||||||
pub fn new(duration: chrono::Duration) -> Self {
|
pub fn new(duration: time::Duration) -> Self {
|
||||||
XsdDuration(duration)
|
XsdDuration(duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the chrono::Duration from an XsdDuration
|
/// Extract the time::Duration from an XsdDuration
|
||||||
pub fn into_inner(self) -> chrono::Duration {
|
pub fn into_inner(self) -> time::Duration {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Borrow the underlying `chrono::Duration`
|
/// Borrow the underlying `time::Duration`
|
||||||
pub fn as_duration(&self) -> &chrono::Duration {
|
pub fn as_duration(&self) -> &time::Duration {
|
||||||
self.as_ref()
|
self.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mutably borrow the underlying `chrono::Duration`
|
/// Mutably borrow the underlying `time::Duration`
|
||||||
pub fn as_duration_mut(&mut self) -> &mut chrono::Duration {
|
pub fn as_duration_mut(&mut self) -> &mut time::Duration {
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<chrono::Duration> for XsdDuration {
|
impl From<time::Duration> for XsdDuration {
|
||||||
fn from(d: chrono::Duration) -> Self {
|
fn from(d: time::Duration) -> Self {
|
||||||
XsdDuration(d)
|
XsdDuration(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<XsdDuration> for chrono::Duration {
|
impl From<XsdDuration> for time::Duration {
|
||||||
fn from(d: XsdDuration) -> Self {
|
fn from(d: XsdDuration) -> Self {
|
||||||
d.0
|
d.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRef<chrono::Duration> for XsdDuration {
|
impl AsRef<time::Duration> for XsdDuration {
|
||||||
fn as_ref(&self) -> &chrono::Duration {
|
fn as_ref(&self) -> &time::Duration {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsMut<chrono::Duration> for XsdDuration {
|
impl AsMut<time::Duration> for XsdDuration {
|
||||||
fn as_mut(&mut self) -> &mut chrono::Duration {
|
fn as_mut(&mut self) -> &mut time::Duration {
|
||||||
&mut self.0
|
&mut self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,12 +147,12 @@ impl std::str::FromStr for XsdDuration {
|
||||||
let (minutes, small) = parse_next(small, 'M')?;
|
let (minutes, small) = parse_next(small, 'M')?;
|
||||||
let (seconds, _) = parse_next(small, 'S')?;
|
let (seconds, _) = parse_next(small, 'S')?;
|
||||||
|
|
||||||
let mut duration = chrono::Duration::days(365 * years);
|
let mut duration = time::Duration::days(365 * years);
|
||||||
duration = duration + chrono::Duration::days(31 * months);
|
duration += time::Duration::days(31 * months);
|
||||||
duration = duration + chrono::Duration::days(days);
|
duration += time::Duration::days(days);
|
||||||
duration = duration + chrono::Duration::hours(hours);
|
duration += time::Duration::hours(hours);
|
||||||
duration = duration + chrono::Duration::minutes(minutes);
|
duration += time::Duration::minutes(minutes);
|
||||||
duration = duration + chrono::Duration::seconds(seconds);
|
duration += time::Duration::seconds(seconds);
|
||||||
|
|
||||||
duration = if negative { duration * -1 } else { duration };
|
duration = if negative { duration * -1 } else { duration };
|
||||||
|
|
||||||
|
@ -174,44 +174,44 @@ fn parse_next(s: &str, c: char) -> Result<(i64, &str), XsdDurationError> {
|
||||||
|
|
||||||
impl std::fmt::Display for XsdDuration {
|
impl std::fmt::Display for XsdDuration {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
let (s, mut duration) = if chrono::Duration::seconds(0) > self.0 {
|
let (s, mut duration) = if time::Duration::seconds(0) > self.0 {
|
||||||
("P-".to_string(), self.0 * -1)
|
("P-".to_string(), self.0 * -1)
|
||||||
} else {
|
} else {
|
||||||
("P".to_string(), self.0)
|
("P".to_string(), self.0)
|
||||||
};
|
};
|
||||||
|
|
||||||
let s = if duration.num_days() > 0 {
|
let s = if duration.whole_days() > 0 {
|
||||||
format!("{}{}D", s, duration.num_days())
|
format!("{}{}D", s, duration.whole_days())
|
||||||
} else {
|
} else {
|
||||||
s
|
s
|
||||||
};
|
};
|
||||||
|
|
||||||
duration = duration - chrono::Duration::days(duration.num_days());
|
duration -= time::Duration::days(duration.whole_days());
|
||||||
|
|
||||||
let s = if duration.num_seconds() > 0 {
|
let s = if duration.whole_seconds() > 0 {
|
||||||
format!("{}T", s)
|
format!("{}T", s)
|
||||||
} else {
|
} else {
|
||||||
s
|
s
|
||||||
};
|
};
|
||||||
|
|
||||||
let s = if duration.num_hours() > 0 {
|
let s = if duration.whole_hours() > 0 {
|
||||||
format!("{}{}H", s, duration.num_hours())
|
format!("{}{}H", s, duration.whole_hours())
|
||||||
} else {
|
} else {
|
||||||
s
|
s
|
||||||
};
|
};
|
||||||
|
|
||||||
duration = duration - chrono::Duration::hours(duration.num_hours());
|
duration -= time::Duration::hours(duration.whole_hours());
|
||||||
|
|
||||||
let s = if duration.num_minutes() > 0 {
|
let s = if duration.whole_minutes() > 0 {
|
||||||
format!("{}{}M", s, duration.num_minutes())
|
format!("{}{}M", s, duration.whole_minutes())
|
||||||
} else {
|
} else {
|
||||||
s
|
s
|
||||||
};
|
};
|
||||||
|
|
||||||
duration = duration - chrono::Duration::minutes(duration.num_minutes());
|
duration -= time::Duration::minutes(duration.whole_minutes());
|
||||||
|
|
||||||
let s = if duration.num_seconds() > 0 {
|
let s = if duration.whole_seconds() > 0 {
|
||||||
format!("{}{}S", s, duration.num_seconds())
|
format!("{}{}S", s, duration.whole_seconds())
|
||||||
} else {
|
} else {
|
||||||
s
|
s
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
//! prelude::*,
|
//! prelude::*,
|
||||||
//! primitives::*,
|
//! primitives::*,
|
||||||
//! unparsed::*,
|
//! unparsed::*,
|
||||||
//! url::Url,
|
//! iri_string::types::IriString,
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
//! /// First, we'll define our public key types
|
//! /// First, we'll define our public key types
|
||||||
|
@ -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: Url,
|
//! pub id: IriString,
|
||||||
//! pub owner: Url,
|
//! pub owner: IriString,
|
||||||
//! pub public_key_pem: String,
|
//! pub public_key_pem: String,
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
|
@ -168,7 +168,7 @@
|
||||||
//! /// And now create helper methods
|
//! /// And now create helper methods
|
||||||
//! pub trait PublicKeyExt<Inner>: AsPublicKey<Inner> {
|
//! pub trait PublicKeyExt<Inner>: AsPublicKey<Inner> {
|
||||||
//! /// Borrow the public key's ID
|
//! /// Borrow the public key's ID
|
||||||
//! fn key_id<'a>(&'a self) -> &'a Url
|
//! fn key_id<'a>(&'a self) -> &'a IriString
|
||||||
//! where
|
//! where
|
||||||
//! Inner: 'a,
|
//! Inner: 'a,
|
||||||
//! {
|
//! {
|
||||||
|
@ -176,13 +176,13 @@
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! /// 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: IriString) -> &mut Self {
|
||||||
//! self.public_key_mut().public_key.id = id;
|
//! self.public_key_mut().public_key.id = id;
|
||||||
//! self
|
//! self
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! /// Borrow the public key's Owner
|
//! /// Borrow the public key's Owner
|
||||||
//! fn key_owner<'a>(&'a self) -> &'a Url
|
//! fn key_owner<'a>(&'a self) -> &'a IriString
|
||||||
//! where
|
//! where
|
||||||
//! Inner: 'a,
|
//! Inner: 'a,
|
||||||
//! {
|
//! {
|
||||||
|
@ -190,7 +190,7 @@
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! /// 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: IriString) -> &mut Self {
|
||||||
//! self.public_key_mut().public_key.owner = owner;
|
//! self.public_key_mut().public_key.owner = owner;
|
||||||
//! self
|
//! self
|
||||||
//! }
|
//! }
|
||||||
|
@ -221,30 +221,30 @@
|
||||||
//!
|
//!
|
||||||
//!
|
//!
|
||||||
//! /// Now that eveything is implemented, we can use it like so:
|
//! /// Now that eveything is implemented, we can use it like so:
|
||||||
//! use activitystreams::{actor::{kind::PersonType, Person}, uri};
|
//! use activitystreams::{actor::{kind::PersonType, Person}, fragment, iri};
|
||||||
//!
|
//!
|
||||||
//! pub type ExtendedPerson = PublicKey<ApActor<Person>>;
|
//! pub type ExtendedPerson = PublicKey<ApActor<Person>>;
|
||||||
//!
|
//!
|
||||||
//! impl ExtendedPerson {
|
//! impl ExtendedPerson {
|
||||||
//! pub fn new(inbox: Url, mut owner: Url) -> Self {
|
//! pub fn new(inbox: IriString, mut owner: IriString) -> Result<Self, anyhow::Error> {
|
||||||
//! let id = owner.clone();
|
//! let id = owner.clone();
|
||||||
//! owner.set_fragment(Some("main-key"));
|
//! owner.set_fragment(Some(fragment!("main-key").as_ref()));
|
||||||
//! PublicKey {
|
//! Ok(PublicKey {
|
||||||
//! public_key: PublicKeyValues {
|
//! public_key: PublicKeyValues {
|
||||||
//! id,
|
//! id,
|
||||||
//! owner,
|
//! owner,
|
||||||
//! public_key_pem: String::new(),
|
//! public_key_pem: String::new(),
|
||||||
//! },
|
//! },
|
||||||
//! inner: ApActor::new(inbox, Person::new()),
|
//! inner: ApActor::new(inbox, Person::new()),
|
||||||
//! }
|
//! })
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! fn main() -> Result<(), anyhow::Error> {
|
//! fn main() -> Result<(), anyhow::Error> {
|
||||||
//! let mut extended_person = ExtendedPerson::new(
|
//! let mut extended_person = ExtendedPerson::new(
|
||||||
//! uri!("https://example.com/user/inbox"),
|
//! iri!("https://example.com/user/inbox"),
|
||||||
//! uri!("https://example.com/user"),
|
//! iri!("https://example.com/user"),
|
||||||
//! );
|
//! )?;
|
||||||
//!
|
//!
|
||||||
//! extended_person
|
//! extended_person
|
||||||
//! .set_kind(PersonType::Person)
|
//! .set_kind(PersonType::Person)
|
||||||
|
|
Loading…
Reference in a new issue