Document icon, image, tag methods
This commit is contained in:
parent
f0d8b27b23
commit
bdf4abc849
1 changed files with 359 additions and 0 deletions
359
src/object.rs
359
src/object.rs
|
@ -387,6 +387,154 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Fetch the icon for the current object
|
||||
///
|
||||
/// ```rust
|
||||
/// # use activitystreams_new::object::Video;
|
||||
/// # let mut video = Video::default();
|
||||
/// #
|
||||
/// use activitystreams_new::prelude::*;
|
||||
///
|
||||
/// if let Some(icon) = video.icon() {
|
||||
/// println!("{:?}", icon);
|
||||
/// }
|
||||
/// ```
|
||||
fn icon<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
|
||||
where
|
||||
Kind: 'a,
|
||||
{
|
||||
self.object_ref().icon.as_ref()
|
||||
}
|
||||
|
||||
/// Set the icon for the current object
|
||||
///
|
||||
/// This overwrites the contents of icon
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// use activitystreams_new::prelude::*;
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
///
|
||||
/// video.set_icon("https://example.com".parse::<XsdAnyUri>()?);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn set_icon<T>(&mut self, icon: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyBase>,
|
||||
{
|
||||
self.object_mut().icon = Some(icon.into().into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set many icons for the current object
|
||||
///
|
||||
/// This overwrites the contents of icon
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// use activitystreams_new::prelude::*;
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
///
|
||||
/// video.set_many_icons(vec![
|
||||
/// "https://example.com/one".parse::<XsdAnyUri>()?,
|
||||
/// "https://example.com/two".parse()?,
|
||||
/// ]);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn set_many_icons<I, T>(&mut self, items: I) -> &mut Self
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<AnyBase>,
|
||||
{
|
||||
let v: Vec<_> = items.into_iter().map(Into::into).collect();
|
||||
self.object_mut().icon = Some(v.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Add a icon to the current object
|
||||
///
|
||||
/// This does not overwrite the contents of icon, only appends an item
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// use activitystreams_new::prelude::*;
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
///
|
||||
/// video
|
||||
/// .add_icon("https://example.com/one".parse::<XsdAnyUri>()?)
|
||||
/// .add_icon("https://example.com/two".parse::<XsdAnyUri>()?);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn add_icon<T>(&mut self, icon: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyBase>,
|
||||
{
|
||||
let a = match self.object_mut().icon.take() {
|
||||
Some(mut a) => {
|
||||
a.add(icon.into());
|
||||
a
|
||||
}
|
||||
None => vec![icon.into()].into(),
|
||||
};
|
||||
self.object_mut().icon = Some(a);
|
||||
self
|
||||
}
|
||||
|
||||
/// Take the icon from the current object, leaving nothing
|
||||
///
|
||||
/// ```rust
|
||||
/// # use activitystreams_new::object::Video;
|
||||
/// # let mut video = Video::default();
|
||||
/// #
|
||||
/// use activitystreams_new::prelude::*;
|
||||
///
|
||||
/// if let Some(icon) = video.take_icon() {
|
||||
/// println!("{:?}", icon);
|
||||
/// }
|
||||
/// ```
|
||||
fn take_icon(&mut self) -> Option<OneOrMany<AnyBase>> {
|
||||
self.object_mut().icon.take()
|
||||
}
|
||||
|
||||
/// Delete the icon from the current object
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
/// # video.set_icon("https://example.com".parse::<XsdAnyUri>()?);
|
||||
/// #
|
||||
/// use activitystreams_new::prelude::*;
|
||||
///
|
||||
/// assert!(video.icon().is_some());
|
||||
/// video.delete_icon();
|
||||
/// assert!(video.icon().is_none());
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn delete_icon(&mut self) -> &mut Self {
|
||||
self.object_mut().icon = None;
|
||||
self
|
||||
}
|
||||
|
||||
/// Fetch the image for the current object
|
||||
///
|
||||
/// ```rust
|
||||
/// # use activitystreams_new::object::Video;
|
||||
/// # let mut video = Video::default();
|
||||
/// #
|
||||
/// use activitystreams_new::prelude::*;
|
||||
///
|
||||
/// if let Some(image) = video.image() {
|
||||
/// println!("{:?}", image);
|
||||
/// }
|
||||
/// ```
|
||||
fn image<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
|
||||
where
|
||||
Kind: 'a,
|
||||
|
@ -394,6 +542,20 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
|
|||
self.object_ref().image.as_ref()
|
||||
}
|
||||
|
||||
/// Set the image for the current object
|
||||
///
|
||||
/// This overwrites the contents of image
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// use activitystreams_new::prelude::*;
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
///
|
||||
/// video.set_image("https://example.com".parse::<XsdAnyUri>()?);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn set_image<T>(&mut self, image: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyBase>,
|
||||
|
@ -402,6 +564,23 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Set many images for the current object
|
||||
///
|
||||
/// This overwrites the contents of image
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// use activitystreams_new::prelude::*;
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
///
|
||||
/// video.set_many_images(vec![
|
||||
/// "https://example.com/one".parse::<XsdAnyUri>()?,
|
||||
/// "https://example.com/two".parse()?,
|
||||
/// ]);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn set_many_images<I, T>(&mut self, items: I) -> &mut Self
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
|
@ -412,6 +591,22 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Add a image to the current object
|
||||
///
|
||||
/// This does not overwrite the contents of image, only appends an item
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// use activitystreams_new::prelude::*;
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
///
|
||||
/// video
|
||||
/// .add_image("https://example.com/one".parse::<XsdAnyUri>()?)
|
||||
/// .add_image("https://example.com/two".parse::<XsdAnyUri>()?);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn add_image<T>(&mut self, image: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyBase>,
|
||||
|
@ -427,10 +622,38 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Take the image from the current object, leaving nothing
|
||||
///
|
||||
/// ```rust
|
||||
/// # use activitystreams_new::object::Video;
|
||||
/// # let mut video = Video::default();
|
||||
/// #
|
||||
/// use activitystreams_new::prelude::*;
|
||||
///
|
||||
/// if let Some(image) = video.take_image() {
|
||||
/// println!("{:?}", image);
|
||||
/// }
|
||||
/// ```
|
||||
fn take_image(&mut self) -> Option<OneOrMany<AnyBase>> {
|
||||
self.object_mut().image.take()
|
||||
}
|
||||
|
||||
/// Delete the image from the current object
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
/// # video.set_image("https://example.com".parse::<XsdAnyUri>()?);
|
||||
/// #
|
||||
/// use activitystreams_new::prelude::*;
|
||||
///
|
||||
/// assert!(video.image().is_some());
|
||||
/// video.delete_image();
|
||||
/// assert!(video.image().is_none());
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn delete_image(&mut self) -> &mut Self {
|
||||
self.object_mut().image = None;
|
||||
self
|
||||
|
@ -485,6 +708,142 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Fetch the tag for the current object
|
||||
///
|
||||
/// ```rust
|
||||
/// # use activitystreams_new::object::Video;
|
||||
/// # let mut video = Video::default();
|
||||
/// #
|
||||
/// use activitystreams_new::prelude::*;
|
||||
///
|
||||
/// if let Some(tag) = video.tag() {
|
||||
/// println!("{:?}", tag);
|
||||
/// }
|
||||
/// ```
|
||||
fn tag<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
|
||||
where
|
||||
Kind: 'a,
|
||||
{
|
||||
self.object_ref().tag.as_ref()
|
||||
}
|
||||
|
||||
/// Set the tag for the current object
|
||||
///
|
||||
/// This overwrites the contents of tag
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// use activitystreams_new::prelude::*;
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
///
|
||||
/// video.set_tag("https://example.com".parse::<XsdAnyUri>()?);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn set_tag<T>(&mut self, tag: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyBase>,
|
||||
{
|
||||
self.object_mut().tag = Some(tag.into().into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set many tags for the current object
|
||||
///
|
||||
/// This overwrites the contents of tag
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// use activitystreams_new::prelude::*;
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
///
|
||||
/// video.set_many_tags(vec![
|
||||
/// "https://example.com/one".parse::<XsdAnyUri>()?,
|
||||
/// "https://example.com/two".parse()?,
|
||||
/// ]);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn set_many_tags<I, T>(&mut self, items: I) -> &mut Self
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<AnyBase>,
|
||||
{
|
||||
let v: Vec<_> = items.into_iter().map(Into::into).collect();
|
||||
self.object_mut().tag = Some(v.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Add a tag to the current object
|
||||
///
|
||||
/// This does not overwrite the contents of tag, only appends an item
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// use activitystreams_new::prelude::*;
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
///
|
||||
/// video
|
||||
/// .add_tag("https://example.com/one".parse::<XsdAnyUri>()?)
|
||||
/// .add_tag("https://example.com/two".parse::<XsdAnyUri>()?);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn add_tag<T>(&mut self, tag: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyBase>,
|
||||
{
|
||||
let a = match self.object_mut().tag.take() {
|
||||
Some(mut a) => {
|
||||
a.add(tag.into());
|
||||
a
|
||||
}
|
||||
None => vec![tag.into()].into(),
|
||||
};
|
||||
self.object_mut().tag = Some(a);
|
||||
self
|
||||
}
|
||||
|
||||
/// Take the tag from the current object, leaving nothing
|
||||
///
|
||||
/// ```rust
|
||||
/// # use activitystreams_new::object::Video;
|
||||
/// # let mut video = Video::default();
|
||||
/// #
|
||||
/// use activitystreams_new::prelude::*;
|
||||
///
|
||||
/// if let Some(tag) = video.take_tag() {
|
||||
/// println!("{:?}", tag);
|
||||
/// }
|
||||
/// ```
|
||||
fn take_tag(&mut self) -> Option<OneOrMany<AnyBase>> {
|
||||
self.object_mut().tag.take()
|
||||
}
|
||||
|
||||
/// Delete the tag from the current object
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// # use activitystreams_new::{object::Video, primitives::XsdAnyUri};
|
||||
/// # let mut video = Video::default();
|
||||
/// # video.set_tag("https://example.com".parse::<XsdAnyUri>()?);
|
||||
/// #
|
||||
/// use activitystreams_new::prelude::*;
|
||||
///
|
||||
/// assert!(video.tag().is_some());
|
||||
/// video.delete_tag();
|
||||
/// assert!(video.tag().is_none());
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
fn delete_tag(&mut self) -> &mut Self {
|
||||
self.object_mut().tag = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn start_time<'a>(&'a self) -> Option<&'a XsdDateTime>
|
||||
where
|
||||
Kind: 'a,
|
||||
|
|
Loading…
Reference in a new issue