[−][src]Trait activitystreams::base::BaseExt
Helper methods for interacting with Base types
This trait represents methods valid for Any ActivityStreams type, regardless of whether it's a Link or an Object.
Documentation for the fields related to these methods can be found on the Base
struct
Provided methods
fn context<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>> where
Kind: 'a,
Kind: 'a,
Fetch the context for the current object
use activitystreams::prelude::*; let video_context = video.context();
fn set_context<T>(&mut self, context: T) -> &mut Self where
T: Into<AnyBase>,
T: Into<AnyBase>,
Set the context for the current object
This overwrites the contents of context
use activitystreams::{context, prelude::*}; video.set_context(context());
fn set_many_contexts<I, T>(&mut self, items: I) -> &mut Self where
I: IntoIterator<Item = T>,
T: Into<AnyBase>,
I: IntoIterator<Item = T>,
T: Into<AnyBase>,
Set many contexts for the current object
This overwrites the contents of context
use activitystreams::{context, prelude::*, security}; video.set_many_contexts(vec![context(), security()]);
fn add_context<T>(&mut self, context: T) -> &mut Self where
T: Into<AnyBase>,
T: Into<AnyBase>,
Add a context to the current object
This does not overwrite the contents of context, only appends a new item
use activitystreams::{context, prelude::*, security}; video .add_context(context()) .add_context(security());
fn take_context(&mut self) -> Option<OneOrMany<AnyBase>>
Take the context from the current object, leaving nothing
use activitystreams::prelude::*; if let Some(context) = video.take_context() { println!("{:?}", context); }
fn delete_context(&mut self) -> &mut Self
Delete the context from the current object
use activitystreams::prelude::*; assert!(video.context().is_some()); video.delete_context(); assert!(video.context().is_none());
fn id<'a>(&'a self, domain: &str) -> Result<Option<&'a Url>, DomainError> where
Kind: 'a,
Kind: 'a,
Fetch the id for the current object, checking it against the provided domain
use activitystreams::prelude::*; assert_eq!(video.id("example.com")?, Some(&uri!("https://example.com")));
fn id_unchecked<'a>(&'a self) -> Option<&'a Url> where
Kind: 'a,
Kind: 'a,
Fetch the id for the current object
use activitystreams::prelude::*; if let Some(id) = video.id_unchecked() { println!("{:?}", id); }
fn id_mut<'a>(&'a mut self) -> Option<&'a mut Url> where
Kind: 'a,
Kind: 'a,
Mutably borrow the ID from the current object
use activitystreams::prelude::*; if let Some(id) = video.id_mut() { id.set_path("/actor"); println!("{:?}", id); }
fn is_id(&self, id: &Url) -> bool
Check if the provided id is equal to the object's id
use activitystreams::{object::Video, prelude::*, uri}; let video: Video = serde_json::from_str(r#"{"type":"Video","id":"https://example.com"}"#)?; assert!(video.is_id(&uri!("https://example.com")));
fn set_id(&mut self, id: Url) -> &mut Self
Set the id for the current object
This overwrites the contents of id
use activitystreams::{prelude::*, uri}; video.set_id(uri!("https://example.com"));
fn take_id(&mut self) -> Option<Url>
Take the id from the current object, leaving nothing
use activitystreams::prelude::*; if let Some(id) = video.take_id() { println!("{:?}", id); }
fn delete_id(&mut self) -> &mut Self
Delete the id from the current object
use activitystreams::prelude::*; assert!(video.id_unchecked().is_some()); video.delete_id(); assert!(video.id_unchecked().is_none());
fn kind<'a>(&'a self) -> Option<&'a Kind> where
Kind: 'a,
Kind: 'a,
Fetch the kind for the current object
use activitystreams::prelude::*; if let Some(kind) = video.kind() { println!("{:?}", kind); }
fn is_kind(&self, kind: &Kind) -> bool where
Kind: PartialEq,
Kind: PartialEq,
Check if the provided Kind is equal to the object's Kind
use activitystreams::{base::Base, prelude::*}; #[derive(PartialEq, serde::Deserialize)] pub enum ValidKinds { Video, Image, } let video: Base<ValidKinds> = serde_json::from_str(r#"{"type":"Video"}"#)?; assert!(video.is_kind(&ValidKinds::Video));
fn set_kind(&mut self, kind: Kind) -> &mut Self
Set the kind for the current object
This overwrites the contents of kind
use activitystreams::prelude::*; video.set_kind(VideoType::Video);
fn take_kind(&mut self) -> Option<Kind>
Take the kind from the current object, leaving nothing
use activitystreams::prelude::*; if let Some(kind) = video.take_kind() { println!("{:?}", kind); }
fn delete_kind(&mut self) -> &mut Self
Delete the kind from the current object
use activitystreams::prelude::*; assert!(video.kind().is_some()); video.delete_kind(); assert!(video.kind().is_none());
fn name<'a>(&'a self) -> Option<OneOrMany<&'a AnyString>> where
Kind: 'a,
Kind: 'a,
Fetch the name for the current object
use activitystreams::prelude::*; if let Some(name) = video.name() { println!("{:?}", name); }
fn set_name<T>(&mut self, name: T) -> &mut Self where
T: Into<AnyString>,
T: Into<AnyString>,
Set the name for the current object
This overwrites the contents of name
use activitystreams::prelude::*; video.set_name("hi");
fn set_many_names<I, T>(&mut self, items: I) -> &mut Self where
I: IntoIterator<Item = T>,
T: Into<AnyString>,
I: IntoIterator<Item = T>,
T: Into<AnyString>,
Set many names for the current object
This overwrites the contents of name
use activitystreams::prelude::*; video.set_many_names(vec!["hi", "hey"]);
fn add_name<T>(&mut self, name: T) -> &mut Self where
T: Into<AnyString>,
T: Into<AnyString>,
Add a name to the current object
This does not overwrite the contents of name, only appends a new item
use activitystreams::prelude::*; video .add_name("hi") .add_name("hey");
fn take_name(&mut self) -> Option<OneOrMany<AnyString>>
Take the name from the current object, leaving nothing
use activitystreams::prelude::*; if let Some(name) = video.take_name() { println!("{:?}", name); }
fn delete_name(&mut self) -> &mut Self
Delete the name from the current object
use activitystreams::prelude::*; assert!(video.name().is_some()); video.delete_name(); assert!(video.name().is_none());
fn media_type<'a>(&'a self) -> Option<&'a Mime> where
Kind: 'a,
Kind: 'a,
Fetch the media type for the current object
use activitystreams::prelude::*; if let Some(media_type) = video.media_type() { println!("{:?}", media_type); }
fn set_media_type(&mut self, media_type: Mime) -> &mut Self
Set the media type for the current object
This overwrites the contents of media_type
use activitystreams::prelude::*; video.set_media_type("video/webm".parse()?);
fn take_media_type(&mut self) -> Option<Mime>
Take the media type from the current object, leaving nothing
use activitystreams::prelude::*; if let Some(media_type) = video.take_media_type() { println!("{:?}", media_type); }
fn delete_media_type(&mut self) -> &mut Self
Delete the media type from the current object
use activitystreams::prelude::*; assert!(video.media_type().is_some()); video.delete_media_type(); assert!(video.media_type().is_none());
fn preview<'a>(&'a self) -> Option<OneOrMany<&'a AnyBase>> where
Kind: 'a,
Kind: 'a,
Fetch the preview for the current object
use activitystreams::prelude::*; if let Some(preview) = video.preview() { println!("{:?}", preview); }
fn set_preview<T>(&mut self, preview: T) -> &mut Self where
T: Into<AnyBase>,
T: Into<AnyBase>,
Set the preview for the current object
This overwrites the contents of preview
use activitystreams::prelude::*; video.set_preview(uri!("https://example.com"));
fn set_many_previews<I, T>(&mut self, items: I) -> &mut Self where
I: IntoIterator<Item = T>,
T: Into<AnyBase>,
I: IntoIterator<Item = T>,
T: Into<AnyBase>,
Set many previews for the current object
This overwrites the contents of preview
use activitystreams::prelude::*; video.set_many_previews(vec![ uri!("https://example.com/one"), uri!("https://example.com/two"), ]);
fn add_preview<T>(&mut self, preview: T) -> &mut Self where
T: Into<AnyBase>,
T: Into<AnyBase>,
Add a preview to the current object
This does not overwrite the contents of preview, only appends an item
use activitystreams::prelude::*; video .add_preview(uri!("https://example.com/one")) .add_preview(uri!("https://example.com/two"));
fn take_preview(&mut self) -> Option<OneOrMany<AnyBase>>
Take the preview from the current object, leaving nothing
use activitystreams::prelude::*; if let Some(preview) = video.take_preview() { println!("{:?}", preview); }
fn delete_preview(&mut self) -> &mut Self
Delete the preview from the current object
use activitystreams::prelude::*; assert!(video.preview().is_some()); video.delete_preview(); assert!(video.preview().is_none());