Introduce 'uri' macro

This commit is contained in:
asonix 2020-06-03 15:35:45 -05:00
parent 05a2bdc98d
commit 0979abb694
8 changed files with 541 additions and 732 deletions

View file

@ -2,7 +2,7 @@ use activitystreams_new::{
context,
object::{ApObject, Video},
prelude::*,
primitives::XsdAnyUri,
uri,
};
fn main() -> Result<(), anyhow::Error> {
@ -10,12 +10,12 @@ fn main() -> Result<(), anyhow::Error> {
video
.set_context(context())
.set_id("https://example.com/@example/lions".parse()?)
.set_id(uri!("https://example.com/@example/lions"))
.set_media_type("video/webm".parse()?)
.set_url("https://example.com/@example/lions/video.webm".parse::<XsdAnyUri>()?)
.set_url(uri!("https://example.com/@example/lions/video.webm"))
.set_summary("A cool video".to_owned())
.set_duration("PT4M20S".parse()?)
.set_shares("https://example.com/@example/lions/video.webm#shares".parse()?);
.set_shares(uri!("https://example.com/@example/lions/video.webm#shares"));
println!("Video, {:#?}", video);

View file

@ -6,18 +6,18 @@
//! activity::Create,
//! context,
//! prelude::*,
//! primitives::XsdAnyUri,
//! uri,
//! };
//!
//! let mut create = Create::new(
//! "https://example.com/actors/abcd".parse::<XsdAnyUri>()?,
//! "https://example.com/notes/1234".parse::<XsdAnyUri>()?,
//! uri!("https://example.com/actors/abcd"),
//! uri!("https://example.com/notes/1234"),
//! );
//!
//! create
//! .set_result("https://example.com/".parse::<XsdAnyUri>()?)
//! .set_instrument("https://example.com/".parse::<XsdAnyUri>()?)
//! .set_id("https://example.com/activities/abcd".parse()?)
//! .set_result(uri!("https://example.com/"))
//! .set_instrument(uri!("https://example.com/"))
//! .set_id(uri!("https://example.com/activities/abcd"))
//! .set_context(context());
//! # Ok(())
//! # }
@ -164,10 +164,10 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question.set_result("https://example.com".parse::<XsdAnyUri>()?);
/// question.set_result(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -186,12 +186,12 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question.set_many_results(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -212,13 +212,13 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// use activitystreams_new::{prelude::*, uri};
/// # use activitystreams_new::{activity::Question};
/// # let mut question = Question::new();
///
/// question
/// .add_result("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_result("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_result(uri!("https://example.com/one"))
/// .add_result(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -257,9 +257,9 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
/// # question.set_result("https://example.com".parse::<XsdAnyUri>()?);
/// # question.set_result(uri!("https://example.com"));
/// #
/// use activitystreams_new::prelude::*;
///
@ -300,10 +300,10 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question.set_instrument("https://example.com".parse::<XsdAnyUri>()?);
/// question.set_instrument(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -322,12 +322,12 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question.set_many_instruments(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -349,12 +349,12 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question
/// .add_instrument("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_instrument("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_instrument(uri!("https://example.com/one"))
/// .add_instrument(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -393,9 +393,9 @@ pub trait ActivityExt<Kind>: AsActivity<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
/// # question.set_instrument("https://example.com".parse::<XsdAnyUri>()?);
/// # question.set_instrument(uri!("https://example.com"));
/// #
/// use activitystreams_new::prelude::*;
///
@ -435,17 +435,13 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # context,
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Create, uri};
/// # let mut create = Create::new(context(), context());
/// use activitystreams_new::prelude::*;
///
/// create.set_actor("https://example.com".parse::<XsdAnyUri>()?);
/// create.set_actor(uri!("https://example.com"));
///
/// assert!(create.actor_is(&"https://example.com".parse()?));
/// assert!(create.actor_is(&uri!("https://example.com")));
/// # Ok(())
/// # }
/// ```
@ -460,14 +456,10 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Create, uri};
/// # let mut create = Create::new(context(), context());
///
/// create.set_actor("https://example.com".parse::<XsdAnyUri>()?);
/// create.set_actor(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -486,16 +478,12 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Create, uri};
/// # let mut create = Create::new(context(), context());
///
/// create.set_many_actors(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -517,16 +505,12 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Create, uri};
/// # let mut create = Create::new(context(), context());
///
/// create
/// .add_actor("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_actor("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_actor(uri!("https://example.com/one"))
/// .add_actor(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -557,17 +541,13 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # context,
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Create, uri};
/// # let mut create = Create::new(context(), context());
/// use activitystreams_new::prelude::*;
///
/// create.set_object("https://example.com".parse::<XsdAnyUri>()?);
/// create.set_object(uri!("https://example.com"));
///
/// assert!(create.object_is(&"https://example.com".parse()?));
/// assert!(create.object_is(&uri!("https://example.com")));
/// # Ok(())
/// # }
/// ```
@ -582,14 +562,10 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Create, uri};
/// # let mut create = Create::new(context(), context());
///
/// create.set_object("https://example.com".parse::<XsdAnyUri>()?);
/// create.set_object(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -608,16 +584,12 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Create, uri};
/// # let mut create = Create::new(context(), context());
///
/// create.set_many_objects(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -639,16 +611,12 @@ pub trait ActorAndObjectRefExt: ActorAndObjectRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Create,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Create, uri};
/// # let mut create = Create::new(context(), context());
///
/// create
/// .add_object("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_object("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_object(uri!("https://example.com/one"))
/// .add_object(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -687,14 +655,10 @@ pub trait TargetRefExt: TargetRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Invite,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Invite, uri};
/// # let mut invite = Invite::new(context(), context(), context());
///
/// invite.set_target("https://example.com".parse::<XsdAnyUri>()?);
/// invite.set_target(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -713,16 +677,12 @@ pub trait TargetRefExt: TargetRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Invite,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Invite, uri};
/// # let mut invite = Invite::new(context(), context(), context());
///
/// invite.set_many_targets(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -744,16 +704,12 @@ pub trait TargetRefExt: TargetRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Invite,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Invite, uri};
/// # let mut invite = Invite::new(context(), context(), context());
///
/// invite
/// .add_target("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_target("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_target(uri!("https://example.com/one"))
/// .add_target(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -792,14 +748,10 @@ pub trait OriginRefExt: OriginRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Arrive,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Arrive, uri};
/// # let mut arrive = Arrive::new(context(), context());
///
/// arrive.set_origin("https://example.com".parse::<XsdAnyUri>()?);
/// arrive.set_origin(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -818,16 +770,12 @@ pub trait OriginRefExt: OriginRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Arrive,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Arrive, uri};
/// # let mut arrive = Arrive::new(context(), context());
///
/// arrive.set_many_origins(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -849,16 +797,12 @@ pub trait OriginRefExt: OriginRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Arrive,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Arrive, uri};
/// # let mut arrive = Arrive::new(context(), context());
///
/// arrive
/// .add_origin("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_origin("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_origin(uri!("https://example.com/one"))
/// .add_origin(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -899,14 +843,10 @@ pub trait OptTargetRefExt: OptTargetRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Announce,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Announce, uri};
/// # let mut announce = Announce::new(context(), context());
///
/// announce.set_target("https://example.com".parse::<XsdAnyUri>()?);
/// announce.set_target(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -925,16 +865,12 @@ pub trait OptTargetRefExt: OptTargetRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Announce,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Announce, uri};
/// # let mut announce = Announce::new(context(), context());
///
/// announce.set_many_targets(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -956,16 +892,12 @@ pub trait OptTargetRefExt: OptTargetRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Announce,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Announce, uri};
/// # let mut announce = Announce::new(context(), context());
///
/// announce
/// .add_target("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_target("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_target(uri!("https://example.com/one"))
/// .add_target(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -992,7 +924,6 @@ pub trait OptTargetRefExt: OptTargetRef {
/// # use activitystreams_new::{
/// # context,
/// # activity::Announce,
/// # primitives::XsdAnyUri
/// # };
/// # let mut announce = Announce::new(context(), context());
///
@ -1014,7 +945,6 @@ pub trait OptTargetRefExt: OptTargetRef {
/// # use activitystreams_new::{
/// # context,
/// # activity::Announce,
/// # primitives::XsdAnyUri
/// # };
/// # let mut announce = Announce::new(context(), context());
/// # announce.set_target(context());
@ -1059,14 +989,10 @@ pub trait OptOriginRefExt: OptOriginRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Delete,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Delete, uri};
/// # let mut delete = Delete::new(context(), context());
///
/// delete.set_origin("https://example.com".parse::<XsdAnyUri>()?);
/// delete.set_origin(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -1085,16 +1011,12 @@ pub trait OptOriginRefExt: OptOriginRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Delete,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Delete, uri};
/// # let mut delete = Delete::new(context(), context());
///
/// delete.set_many_origins(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -1116,16 +1038,12 @@ pub trait OptOriginRefExt: OptOriginRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Delete,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Delete, uri};
/// # let mut delete = Delete::new(context(), context());
///
/// delete
/// .add_origin("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_origin("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_origin(uri!("https://example.com/one"))
/// .add_origin(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -1149,11 +1067,7 @@ pub trait OptOriginRefExt: OptOriginRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Delete,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Delete};
/// # let mut delete = Delete::new(context(), context());
///
/// if let Some(origin) = delete.take_origin() {
@ -1171,11 +1085,7 @@ pub trait OptOriginRefExt: OptOriginRef {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # activity::Delete,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, activity::Delete};
/// # let mut delete = Delete::new(context(), context());
/// # delete.set_origin(context());
///
@ -1221,10 +1131,10 @@ pub trait QuestionExt: AsQuestion {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question.set_one_of("https://example.com".parse::<XsdAnyUri>()?);
/// question.set_one_of(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -1243,12 +1153,12 @@ pub trait QuestionExt: AsQuestion {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question.set_many_one_ofs(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -1270,12 +1180,12 @@ pub trait QuestionExt: AsQuestion {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question
/// .add_one_of("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_one_of("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_one_of(uri!("https://example.com/one"))
/// .add_one_of(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -1314,9 +1224,9 @@ pub trait QuestionExt: AsQuestion {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
/// # question.set_one_of("https://example.com".parse::<XsdAnyUri>()?);
/// # question.set_one_of(uri!("https://example.com"));
/// #
/// use activitystreams_new::prelude::*;
///
@ -1354,10 +1264,10 @@ pub trait QuestionExt: AsQuestion {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question.set_any_of("https://example.com".parse::<XsdAnyUri>()?);
/// question.set_any_of(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -1376,12 +1286,12 @@ pub trait QuestionExt: AsQuestion {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question.set_many_any_ofs(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -1403,12 +1313,12 @@ pub trait QuestionExt: AsQuestion {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
///
/// question
/// .add_any_of("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_any_of("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_any_of(uri!("https://example.com/one"))
/// .add_any_of(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -1447,9 +1357,9 @@ pub trait QuestionExt: AsQuestion {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{activity::Question, primitives::XsdAnyUri};
/// # use activitystreams_new::{activity::Question, uri};
/// # let mut question = Question::new();
/// # question.set_any_of("https://example.com".parse::<XsdAnyUri>()?);
/// # question.set_any_of(uri!("https://example.com"));
/// #
/// use activitystreams_new::prelude::*;
///

View file

@ -5,18 +5,18 @@
//! use activitystreams_new::{
//! actor::{ApActor, Person},
//! prelude::*,
//! primitives::XsdAnyUri,
//! uri,
//! };
//!
//! let mut person = ApActor::new(
//! "https://example.com/actor/inbox".parse()?,
//! uri!("https://example.com/actor/inbox"),
//! Person::new(),
//! );
//!
//! person
//! .set_outbox("https://example.com/actor/outbox".parse()?)
//! .set_following("https://example.com/actor/following".parse()?)
//! .set_followers("https://example.com/actor/followers".parse()?);
//! .set_outbox(uri!("https://example.com/actor/outbox"))
//! .set_following(uri!("https://example.com/actor/following"))
//! .set_followers(uri!("https://example.com/actor/followers"));
//! #
//! # Ok(())
//! # }
@ -78,11 +78,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// use activitystreams_new::prelude::*;
///
/// person.set_inbox("https://example.com/inbox".parse()?);
/// person.set_inbox(uri!("https://example.com/inbox"));
/// # Ok(())
/// # }
/// ```
@ -111,11 +111,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// use activitystreams_new::prelude::*;
///
/// person.set_outbox("https://example.com/outbox".parse()?);
/// person.set_outbox(uri!("https://example.com/outbox"));
/// # Ok(())
/// # }
/// ```
@ -143,9 +143,9 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// # person.set_outbox("https://example.com/outbox".parse()?);
/// # person.set_outbox(uri!("https://example.com/outbox"));
/// use activitystreams_new::prelude::*;
///
/// assert!(person.outbox().is_some());
@ -181,11 +181,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// use activitystreams_new::prelude::*;
///
/// person.set_following("https://example.com/following".parse()?);
/// person.set_following(uri!("https://example.com/following"));
/// # Ok(())
/// # }
/// ```
@ -213,9 +213,9 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// # person.set_following("https://example.com/following".parse()?);
/// # person.set_following(uri!("https://example.com/following"));
/// use activitystreams_new::prelude::*;
///
/// assert!(person.following().is_some());
@ -251,11 +251,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// use activitystreams_new::prelude::*;
///
/// person.set_followers("https://example.com/followers".parse()?);
/// person.set_followers(uri!("https://example.com/followers"));
/// # Ok(())
/// # }
/// ```
@ -283,9 +283,9 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// # person.set_followers("https://example.com/followers".parse()?);
/// # person.set_followers(uri!("https://example.com/followers"));
/// use activitystreams_new::prelude::*;
///
/// assert!(person.followers().is_some());
@ -321,11 +321,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// use activitystreams_new::prelude::*;
///
/// person.set_streams("https://example.com/liked".parse()?);
/// person.set_streams(uri!("https://example.com/liked"));
/// # Ok(())
/// # }
/// ```
@ -353,9 +353,9 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// # person.set_liked("https://example.com/liked".parse()?);
/// # person.set_liked(uri!("https://example.com/liked"));
/// use activitystreams_new::prelude::*;
///
/// assert!(person.liked().is_some());
@ -391,11 +391,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// use activitystreams_new::prelude::*;
///
/// person.set_streams("https://example.com/streams".parse()?);
/// person.set_streams(uri!("https://example.com/streams"));
/// # Ok(())
/// # }
/// ```
@ -408,13 +408,13 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// use activitystreams_new::prelude::*;
///
/// person.set_many_streams(vec![
/// "https://example.com/streams1".parse()?,
/// "https://example.com/streams2".parse()?
/// uri!("https://example.com/streams1"),
/// uri!("https://example.com/streams2"),
/// ]);
/// # Ok(())
/// # }
@ -432,13 +432,13 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// use activitystreams_new::prelude::*;
///
/// person
/// .add_streams("https://example.com/streams1".parse()?)
/// .add_streams("https://example.com/streams2".parse()?);
/// .add_streams(uri!("https://example.com/streams1"))
/// .add_streams(uri!("https://example.com/streams2"));
/// # Ok(())
/// # }
/// ```
@ -473,9 +473,9 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// # person.set_streams("https://example.com/streams".parse()?);
/// # person.set_streams(uri!("https://example.com/streams"));
/// use activitystreams_new::prelude::*;
///
/// assert!(person.streams().is_some());
@ -584,12 +584,12 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{actor::{ApActor, Endpoints, Person}, context};
/// # use activitystreams_new::{actor::{ApActor, Endpoints, Person}, context, uri};
/// # let mut person = ApActor::new(context(), Person::new());
/// use activitystreams_new::prelude::*;
///
/// person.set_endpoints(Endpoints {
/// shared_inbox: Some("https://example.com/inbox".parse()?),
/// shared_inbox: Some(uri!("https://example.com/inbox")),
/// ..Default::default()
/// });
/// # Ok(())
@ -865,10 +865,10 @@ impl<Inner> ApActor<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::actor::{ApActor, Person};
/// use activitystreams_new::{actor::{ApActor, Person}, uri};
///
/// let actor = ApActor::new(
/// "https://example.com/inbox".parse()?,
/// uri!("https://example.com/inbox"),
/// Person::new(),
/// );
/// # Ok(())

View file

@ -8,11 +8,12 @@
//! object::Video,
//! prelude::*,
//! security,
//! uri,
//! };
//! let mut video = Video::new();
//!
//! video
//! .set_id("https://example.com".parse()?)
//! .set_id(uri!("https://example.com"))
//! .set_context(context())
//! .add_context(security())
//! .set_name("Hello");
@ -266,11 +267,11 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::{object::Video, prelude::*};
/// use activitystreams_new::{object::Video, prelude::*, uri};
///
/// let video: Video = serde_json::from_str(r#"{"type":"Video","id":"https://example.com"}"#)?;
///
/// assert!(video.is_id(&"https://example.com".parse()?));
/// assert!(video.is_id(&uri!("https://example.com")));
/// # Ok(())
/// # }
/// ```
@ -287,9 +288,9 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// use activitystreams_new::prelude::*;
/// use activitystreams_new::{prelude::*, uri};
///
/// video.set_id("https://example.com".parse()?);
/// video.set_id(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -648,10 +649,10 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
/// # use activitystreams_new::{object::Video, uri};
/// # let mut video = Video::new();
///
/// video.set_preview("https://example.com".parse::<XsdAnyUri>()?);
/// video.set_preview(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -670,12 +671,12 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
/// # use activitystreams_new::{object::Video, uri};
/// # let mut video = Video::new();
///
/// video.set_many_previews(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -697,12 +698,12 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
/// # use activitystreams_new::{object::Video, uri};
/// # let mut video = Video::new();
///
/// video
/// .add_preview("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_preview("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_preview(uri!("https://example.com/one"))
/// .add_preview(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -741,9 +742,9 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
/// # use activitystreams_new::{object::Video, uri};
/// # let mut video = Video::new();
/// # video.set_preview("https://example.com".parse::<XsdAnyUri>()?);
/// # video.set_preview(uri!("https://example.com"));
/// #
/// use activitystreams_new::prelude::*;
///
@ -1040,9 +1041,9 @@ impl AnyBase {
/// Check if this object is an XsdAnyUri
///
/// ```rust
/// # use activitystreams_new::base::AnyBase;
/// # use activitystreams_new::{base::AnyBase, uri};
/// # fn main() -> Result<(), anyhow::Error> {
/// let any_base = AnyBase::from_xsd_any_uri("https://example.com".parse()?);
/// let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
/// assert!(any_base.is_xsd_any_uri());
/// # Ok(())
/// # }
@ -1092,11 +1093,9 @@ impl AnyBase {
/// #### Get the ID from the nested video
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # object::Video, base::AnyBase, prelude::*, primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{object::Video, base::AnyBase, prelude::*, uri};
/// # let mut video = Video::new();
/// let id = "https://example.com".parse::<XsdAnyUri>()?;
/// let id = uri!("https://example.com");
///
/// video.set_id(id.clone());
///
@ -1109,10 +1108,8 @@ impl AnyBase {
/// #### Get the ID from the AnyBase
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # base::AnyBase, prelude::*, primitives::XsdAnyUri
/// # };
/// let id = "https://example.com".parse::<XsdAnyUri>()?;
/// # use activitystreams_new::{base::AnyBase, prelude::*, uri};
/// let id = uri!("https://example.com");
///
/// let any_base = AnyBase::from_xsd_any_uri(id.clone());
/// assert!(any_base.id().unwrap() == &id);
@ -1129,15 +1126,15 @@ impl AnyBase {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # object::{kind::VideoType, Video}, base::AnyBase, prelude::*,
/// # object::{kind::VideoType, Video}, base::AnyBase, prelude::*, uri
/// # };
/// # let mut video = Video::new();
/// #
/// video.set_id("https://example.com".parse()?);
/// video.set_id(uri!("https://example.com"));
///
/// let any_base = AnyBase::from_extended(video)?;
///
/// assert!(any_base.is_id(&"https://example.com".parse()?));
/// assert!(any_base.is_id(&uri!("https://example.com")));
/// # Ok(())
/// # }
/// ```
@ -1223,9 +1220,9 @@ impl AnyBase {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::base::AnyBase;
/// # use activitystreams_new::{base::AnyBase, uri};
/// #
/// let any_base = AnyBase::from_xsd_any_uri("https://example.com".parse()?);
/// let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
///
/// assert!(any_base.as_xsd_any_uri().is_some());
/// #
@ -1271,9 +1268,9 @@ impl AnyBase {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::base::AnyBase;
/// # use activitystreams_new::{base::AnyBase, uri};
/// #
/// let any_base = AnyBase::from_xsd_any_uri("https://example.com".parse()?);
/// let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
///
/// assert!(any_base.take_xsd_any_uri().is_some());
/// #
@ -1319,11 +1316,11 @@ impl AnyBase {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::base::AnyBase;
/// # use activitystreams_new::{base::AnyBase, uri};
/// #
/// let mut any_base = AnyBase::from_xsd_string("hi".into());
///
/// any_base.set_xsd_any_uri("https://example.com".parse()?);
/// any_base.set_xsd_any_uri(uri!("https://example.com"));
///
/// assert!(any_base.take_xsd_any_uri().is_some());
/// #
@ -1338,19 +1335,22 @@ impl AnyBase {
///
/// ```
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::base::AnyBase;
/// # use activitystreams_new::{base::AnyBase, uri};
/// #
/// let mut any_base = AnyBase::from_xsd_any_uri("https://example.com".parse()?);
/// let mut any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
///
/// any_base.set_xsd_string("hi".into());
/// any_base.set_xsd_string("hi");
///
/// assert!(any_base.take_xsd_string().is_some());
/// #
/// # Ok(())
/// # }
/// ```
pub fn set_xsd_string(&mut self, xsd_string: String) {
self.0 = Either::Right(xsd_string);
pub fn set_xsd_string<T>(&mut self, xsd_string: T)
where
T: Into<String>,
{
self.0 = Either::Right(xsd_string.into());
}
/// Replace the object with the provided `Base<serde_json::Value>`
@ -1377,8 +1377,8 @@ impl AnyBase {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::base::AnyBase;
/// let any_base = AnyBase::from_xsd_any_uri("https://example.com".parse()?);
/// use activitystreams_new::{base::AnyBase, uri};
/// let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -1444,13 +1444,16 @@ impl OneOrMany<AnyBase> {
/// Get the ID from a single object if there is only one object
///
/// ```rust
/// # use activitystreams_new::{base::Base, primitives::{OneOrMany, XsdAnyUri}};
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{base::Base, primitives::OneOrMany, uri};
/// # let mut base = Base::<String>::new();
/// # let id: XsdAnyUri = "https://example.com".parse().unwrap();
/// # let id = uri!("https://example.com");
/// # base.id = Some(id.clone());
/// # let base = OneOrMany::from_base(base.into_generic().unwrap().into());
/// # let base = OneOrMany::from_base(base.into_generic()?.into());
/// #
/// assert!(base.as_single_id() == Some(&id));
/// # Ok(())
/// # }
/// ```
pub fn as_single_id(&self) -> Option<&XsdAnyUri> {
self.as_one().and_then(|one| one.id())
@ -1459,13 +1462,16 @@ impl OneOrMany<AnyBase> {
/// Check if there's only one ID, and if it equals `id`
///
/// ```rust
/// # use activitystreams_new::{base::Base, primitives::{OneOrMany, XsdAnyUri}};
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{base::Base, primitives::OneOrMany, uri};
/// # let mut base = Base::<String>::new();
/// # let id: XsdAnyUri = "https://example.com".parse().unwrap();
/// # let id = uri!("https://example.com");
/// # base.id = Some(id.clone());
/// # let base = OneOrMany::from_base(base.into_generic().unwrap().into());
/// # let base = OneOrMany::from_base(base.into_generic()?.into());
/// #
/// assert!(base.is_single_id(&id));
/// # Ok(())
/// # }
/// ```
pub fn is_single_id(&self, id: &XsdAnyUri) -> bool {
self.as_single_id() == Some(id)
@ -1474,12 +1480,15 @@ impl OneOrMany<AnyBase> {
/// Get the kind of a single object if there is only one object
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{base::Base, primitives::OneOrMany};
/// # let mut base = Base::new();
/// # base.kind = Some(String::from("Person"));
/// # let base = OneOrMany::from_base(base.into_generic().unwrap().into());
/// # let base = OneOrMany::from_base(base.into_generic()?.into());
/// #
/// assert!(base.as_single_kind_str() == Some("Person"));
/// # Ok(())
/// # }
/// ```
pub fn as_single_kind(&self) -> Option<&serde_json::Value> {
self.as_one().and_then(|one| one.kind())
@ -1489,12 +1498,15 @@ impl OneOrMany<AnyBase> {
///
/// This returns None if the kind is not present, or not a String
/// ```
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{base::Base, primitives::OneOrMany};
/// # let mut base = Base::new();
/// # base.kind = Some(String::from("Person"));
/// # let base = OneOrMany::from_base(base.into_generic().unwrap().into());
/// # let base = OneOrMany::from_base(base.into_generic()?.into());
/// #
/// assert!(base.as_single_kind_str() == Some("Person"));
/// # Ok(())
/// # }
/// ```
pub fn as_single_kind_str(&self) -> Option<&str> {
self.as_one().and_then(|one| one.kind_str())
@ -1505,12 +1517,15 @@ impl OneOrMany<AnyBase> {
/// This returns False if the kind is not present, or not a String
///
/// ```
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{base::Base, primitives::OneOrMany};
/// # let mut base = Base::new();
/// # base.kind = Some(String::from("Person"));
/// # let base = OneOrMany::from_base(base.into_generic().unwrap().into());
/// # let base = OneOrMany::from_base(base.into_generic()?.into());
/// #
/// assert!(base.is_single_kind("Person"));
/// # Ok(())
/// # }
/// ```
pub fn is_single_kind(&self, kind: &str) -> bool {
self.as_single_kind_str() == Some(kind)
@ -1520,9 +1535,9 @@ impl OneOrMany<AnyBase> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::primitives::OneOrMany;
/// # use activitystreams_new::{primitives::OneOrMany, uri};
/// #
/// let one = OneOrMany::from_xsd_any_uri("https://example.com".parse()?);
/// let one = OneOrMany::from_xsd_any_uri(uri!("https://example.com"));
///
/// assert!(one.as_single_xsd_any_uri().is_some());
/// #
@ -1564,9 +1579,9 @@ impl OneOrMany<AnyBase> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::primitives::OneOrMany;
/// # use activitystreams_new::{primitives::OneOrMany, uri};
/// #
/// let one = OneOrMany::from_xsd_any_uri("https://example.com".parse()?);
/// let one = OneOrMany::from_xsd_any_uri(uri!("https://example.com"));
///
/// assert!(one.single_xsd_any_uri().is_some());
/// #
@ -1608,9 +1623,9 @@ impl OneOrMany<AnyBase> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::primitives::OneOrMany;
/// use activitystreams_new::{primitives::OneOrMany, uri};
///
/// let one = OneOrMany::from_xsd_any_uri("https://example.com".parse()?);
/// let one = OneOrMany::from_xsd_any_uri(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```

View file

@ -6,19 +6,19 @@
//! collection::OrderedCollection,
//! context,
//! prelude::*,
//! primitives::XsdAnyUri,
//! uri,
//! };
//!
//! let mut collection = OrderedCollection::new(vec![
//! "https://example.com/notes/1234".parse::<XsdAnyUri>()?.into(),
//! uri!("https://example.com/notes/1234").into(),
//! ]);
//!
//! collection
//! .set_total_items(1)
//! .set_current("https://example.com/notes/1234".parse::<XsdAnyUri>()?)
//! .set_first("https://example.com/notes/1234".parse::<XsdAnyUri>()?)
//! .set_last("https://example.com/notes/1234".parse::<XsdAnyUri>()?)
//! .set_id("https://example.com/collections/1234".parse()?)
//! .set_current(uri!("https://example.com/notes/1234"))
//! .set_first(uri!("https://example.com/notes/1234"))
//! .set_last(uri!("https://example.com/notes/1234"))
//! .set_id(uri!("https://example.com/collections/1234"))
//! .set_context(context());
//! # Ok(())
//! # }
@ -101,14 +101,10 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection, uri};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
///
/// collection.set_items("https://example.com".parse::<XsdAnyUri>()?);
/// collection.set_items(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -127,16 +123,12 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection, uri};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
///
/// collection.set_many_items(vec![
/// "https://example.com/one".parse::<XsdAnyUri>()?,
/// "https://example.com/two".parse()?,
/// uri!("https://example.com/one"),
/// uri!("https://example.com/two"),
/// ]);
/// # Ok(())
/// # }
@ -158,16 +150,12 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection, uri};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
///
/// collection
/// .add_items("https://example.com/one".parse::<XsdAnyUri>()?)
/// .add_items("https://example.com/two".parse::<XsdAnyUri>()?);
/// .add_items(uri!("https://example.com/one"))
/// .add_items(uri!("https://example.com/two"));
/// # Ok(())
/// # }
/// ```
@ -182,11 +170,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Fetch the total_items of the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// use activitystreams_new::prelude::*;
///
@ -206,11 +190,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// This overwrites the contents of total_items
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// use activitystreams_new::prelude::*;
///
@ -227,11 +207,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Take the total_items of the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// use activitystreams_new::prelude::*;
///
@ -246,11 +222,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Delete the total_items from the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// # collection.set_total_items(5);
/// use activitystreams_new::prelude::*;
@ -267,11 +239,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Fetch the current field for the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -293,16 +261,12 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection, uri};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
///
/// collection.set_current("https://example.com".parse::<XsdAnyUri>()?);
/// collection.set_current(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -317,11 +281,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Take the current field from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -337,11 +297,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Delete the current field from the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// # collection.set_current(context());
/// #
@ -359,11 +315,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Fetch the first field for the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -385,16 +337,12 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
/// use activitystreams_new::{prelude::*, uri};
///
/// collection.set_first("https://example.com".parse::<XsdAnyUri>()?);
/// collection.set_first(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -409,11 +357,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Take the first field from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -429,11 +373,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Delete the first field from the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// # collection.set_first(context());
/// #
@ -451,11 +391,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Fetch the last field for the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -477,16 +413,12 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
/// use activitystreams_new::{prelude::*, uri};
///
/// collection.set_last("https://example.com".parse::<XsdAnyUri>()?);
/// collection.set_last(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -501,11 +433,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Take the last field from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -521,11 +449,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// Delete the last field from the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollection,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollection};
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
/// # collection.set_last(context());
/// #
@ -551,11 +475,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// Fetch the part_of field for the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -577,16 +497,12 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
/// use activitystreams_new::{prelude::*, uri};
///
/// collection.set_part_of("https://example.com".parse::<XsdAnyUri>()?);
/// collection.set_part_of(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -601,11 +517,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// Take the part_of field from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -621,11 +533,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// Delete the part_of field from the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// # collection.set_part_of(context());
/// #
@ -643,11 +551,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// Fetch the next field for the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -669,16 +573,12 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
/// use activitystreams_new::{prelude::*, uri};
///
/// collection.set_next("https://example.com".parse::<XsdAnyUri>()?);
/// collection.set_next(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -693,11 +593,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// Take the next field from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -713,11 +609,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// Delete the next field from the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// # collection.set_next(context());
/// #
@ -735,11 +627,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// Fetch the prev field for the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -761,16 +649,12 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
/// use activitystreams_new::{prelude::*, uri};
///
/// collection.set_prev("https://example.com".parse::<XsdAnyUri>()?);
/// collection.set_prev(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -785,11 +669,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// Take the prev field from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// #
/// use activitystreams_new::prelude::*;
@ -805,11 +685,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// Delete the prev field from the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::UnorderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::UnorderedCollectionPage};
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
/// # collection.set_prev(context());
/// #
@ -829,11 +705,7 @@ pub trait OrderedCollectionPageExt: AsOrderedCollectionPage {
/// Fetch the start_index of the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::OrderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::OrderedCollectionPage};
/// # let mut collection = OrderedCollectionPage::new(vec![context().into()]);
/// use activitystreams_new::prelude::*;
///
@ -850,11 +722,7 @@ pub trait OrderedCollectionPageExt: AsOrderedCollectionPage {
/// This overwrites the contents of start_index
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::OrderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::OrderedCollectionPage};
/// # let mut collection = OrderedCollectionPage::new(vec![context().into()]);
/// use activitystreams_new::prelude::*;
///
@ -871,11 +739,7 @@ pub trait OrderedCollectionPageExt: AsOrderedCollectionPage {
/// Take the start_index of the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::OrderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::OrderedCollectionPage};
/// # let mut collection = OrderedCollectionPage::new(vec![context().into()]);
/// use activitystreams_new::prelude::*;
///
@ -890,11 +754,7 @@ pub trait OrderedCollectionPageExt: AsOrderedCollectionPage {
/// Delete the start_index from the current object
///
/// ```rust
/// # use activitystreams_new::{
/// # context,
/// # collection::OrderedCollectionPage,
/// # primitives::XsdAnyUri
/// # };
/// # use activitystreams_new::{context, collection::OrderedCollectionPage};
/// # let mut collection = OrderedCollectionPage::new(vec![context().into()]);
/// # collection.set_start_index(5);
/// use activitystreams_new::prelude::*;

View file

@ -164,14 +164,14 @@
//! bound the function like so:
//!
//! ```rust
//! use activitystreams_new::{base::BaseExt, context, markers::Activity};
//! use activitystreams_new::{base::BaseExt, context, markers::Activity, uri};
//!
//! fn manipulator<T, Kind>(mut activity: T) -> Result<(), anyhow::Error>
//! where
//! T: Activity + BaseExt<Kind>,
//! {
//! activity
//! .set_id("https://example.com".parse()?)
//! .set_id(uri!("https://example.com"))
//! .set_context(context());
//! Ok(())
//! }
@ -205,7 +205,7 @@
//! context,
//! object::{ApObject, Video},
//! prelude::*,
//! primitives::XsdAnyUri,
//! uri,
//! };
//!
//! fn main() -> Result<(), anyhow::Error> {
@ -213,12 +213,12 @@
//!
//! video
//! .set_context(context())
//! .set_id("https://example.com/@example/lions".parse()?)
//! .set_id(uri!("https://example.com/@example/lions"))
//! .set_media_type("video/webm".parse()?)
//! .set_url("https://example.com/@example/lions/video.webm".parse::<XsdAnyUri>()?)
//! .set_url(uri!("https://example.com/@example/lions/video.webm"))
//! .set_summary("A cool video")
//! .set_duration("PT4M20S".parse()?)
//! .set_shares("https://example.com/@example/lions/video.webm#shares".parse()?);
//! .set_shares(uri!("https://example.com/@example/lions/video.webm#shares"));
//!
//! println!("Video, {:#?}", video);
//!
@ -332,47 +332,44 @@ pub mod prelude {
//! ```rust
//! # fn main() -> Result<(), anyhow::Error> {
//! use activitystreams_new::{
//! activity::{kind::CreateType, Create},
//! actor::{kind::PersonType, ApActor, Person},
//! activity::Create,
//! actor::{ApActor, Person},
//! context,
//! prelude::*,
//! primitives::XsdAnyUri,
//! public,
//! object::{
//! kind::{ImageType, VideoType},
//! ApObject, Image, Video
//! },
//! security
//! object::{ApObject, Image, Video},
//! security,
//! uri,
//! };
//!
//! let mut person = ApActor::new(
//! "http://localhost:8080/inbox".parse()?,
//! uri!("http://localhost:8080/inbox"),
//! Person::new(),
//! );
//! person
//! .set_outbox("http:/localhost:8080/outbox".parse()?)
//! .set_outbox(uri!("http:/localhost:8080/outbox"))
//! .set_name("Demo Account")
//! .set_preferred_username("demo")
//! .set_id("https://localhost:8080/actor".parse()?)
//! .set_url("https://localhost:8080/actor".parse::<XsdAnyUri>()?);
//! .set_id(uri!("https://localhost:8080/actor"))
//! .set_url(uri!("https://localhost:8080/actor"));
//!
//! let mut preview = Image::new();
//!
//! preview
//! .set_url("https://localhost:8080/preview.png".parse::<XsdAnyUri>()?)
//! .set_url(uri!("https://localhost:8080/preview.png"))
//! .set_media_type("image/png".parse()?)
//! .set_id("https://localhostst:8080/preview.png".parse()?);
//! .set_id(uri!("https://localhostst:8080/preview.png"));
//!
//! let mut video = ApObject::new(Video::new());
//!
//! video
//! .set_id("http://localhost:8080/video.webm".parse()?)
//! .set_url("http://localhost:8080/video.webm".parse::<XsdAnyUri>()?)
//! .set_id(uri!("http://localhost:8080/video.webm"))
//! .set_url(uri!("http://localhost:8080/video.webm"))
//! .set_media_type("video/webm".parse()?)
//! .set_summary("A cool video")
//! .set_preview(preview.into_any_base()?)
//! .set_duration("PT4M20S".parse()?)
//! .set_shares("http://localhost:8080/video.webm#shares".parse()?);
//! .set_shares(uri!("http://localhost:8080/video.webm#shares"));
//!
//! let mut activity = Create::new(
//! person.into_any_base()?,
@ -398,3 +395,24 @@ pub mod prelude {
object::{ApObjectExt, ObjectExt, PlaceExt, ProfileExt, RelationshipExt, TombstoneExt},
};
}
/// A macro to shorten the `string.parse::<XsdAnyUri>()?` calls inevitably made in downstream code
///
/// ```rust
/// use activitystreams_new::uri;
///
/// fn fallible() -> Result<(), anyhow::Error> {
/// let my_uri = uri!("https://example.com");
/// Ok(())
/// }
///
/// # fn main() -> Result<(), anyhow::Error> { fallible() }
/// ```
#[macro_export]
macro_rules! uri {
( $x:expr ) => {{
use activitystreams::primitives::XsdAnyUri;
$x.parse::<XsdAnyUri>()?
}};
}

View file

@ -6,15 +6,15 @@
//! link::Mention,
//! object::Image,
//! prelude::*,
//! primitives::XsdAnyUri,
//! uri,
//! };
//!
//! let mut mention = Mention::new();
//!
//! mention
//! .set_href("https://example.com".parse()?)
//! .set_hreflang("en".into())
//! .set_rel("link".into())
//! .set_href(uri!("https://example.com"))
//! .set_hreflang("en")
//! .set_rel("link")
//! .set_preview(Image::new().into_any_base()?);
//! #
//! # Ok(())
@ -80,12 +80,12 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::link::Mention;
/// # use activitystreams_new::{link::Mention, uri};
/// # let mut mention = Mention::new();
/// #
/// use activitystreams_new::prelude::*;
///
/// mention.set_href("https://example.com".parse()?);
/// mention.set_href(uri!("https://example.com"));
/// # Ok(())
/// # }
/// ```
@ -114,9 +114,9 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::link::Mention;
/// # use activitystreams_new::{link::Mention, uri};
/// # let mut mention = Mention::new();
/// # mention.set_href("https://example.com".parse()?);
/// # mention.set_href(uri!("https://example.com"));
/// #
/// use activitystreams_new::prelude::*;
///
@ -158,10 +158,13 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// #
/// use activitystreams_new::prelude::*;
///
/// mention.set_hreflang("en".into());
/// mention.set_hreflang("en");
/// ```
fn set_hreflang(&mut self, hreflang: String) -> &mut Self {
self.link_mut().hreflang = Some(hreflang);
fn set_hreflang<T>(&mut self, hreflang: T) -> &mut Self
where
T: Into<String>,
{
self.link_mut().hreflang = Some(hreflang.into());
self
}
@ -187,7 +190,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::link::Mention;
/// # let mut mention = Mention::new();
/// # mention.set_hreflang("https://example.com".parse()?);
/// # mention.set_hreflang("en");
/// #
/// use activitystreams_new::prelude::*;
///
@ -229,10 +232,13 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// #
/// use activitystreams_new::prelude::*;
///
/// mention.set_rel("link".into());
/// mention.set_rel("link");
/// ```
fn set_rel(&mut self, rel: String) -> &mut Self {
self.link_mut().rel = Some(rel.into());
fn set_rel<T>(&mut self, rel: T) -> &mut Self
where
T: Into<String>,
{
self.link_mut().rel = Some(rel.into().into());
self
}
@ -304,7 +310,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// ```rust
/// # use activitystreams_new::link::Mention;
/// # let mut mention = Mention::new();
/// # mention.set_rel("link".into());
/// # mention.set_rel("link");
/// #
/// use activitystreams_new::prelude::*;
///

File diff suppressed because it is too large Load diff