[][src]Trait activitystreams_new::base::BaseExt

pub trait BaseExt<Kind>: AsBase<Kind> {
    fn context<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
    where
        Kind: 'a
, { ... }
fn set_context<T>(&mut self, context: T) -> &mut Self
    where
        T: Into<AnyBase>
, { ... }
fn set_many_contexts<I, T>(&mut self, items: I) -> &mut Self
    where
        I: IntoIterator<Item = T>,
        T: Into<AnyBase>
, { ... }
fn add_context<T>(&mut self, context: T) -> &mut Self
    where
        T: Into<AnyBase>
, { ... }
fn take_context(&mut self) -> Option<OneOrMany<AnyBase>> { ... }
fn delete_context(&mut self) -> &mut Self { ... }
fn id<'a>(&'a self, domain: &str) -> Result<Option<&'a Url>, DomainError>
    where
        Kind: 'a
, { ... }
fn id_unchecked<'a>(&'a self) -> Option<&'a Url>
    where
        Kind: 'a
, { ... }
fn id_mut<'a>(&'a mut self) -> Option<&'a mut Url>
    where
        Kind: 'a
, { ... }
fn is_id(&self, id: &Url) -> bool { ... }
fn set_id(&mut self, id: Url) -> &mut Self { ... }
fn take_id(&mut self) -> Option<Url> { ... }
fn delete_id(&mut self) -> &mut Self { ... }
fn kind<'a>(&'a self) -> Option<&'a Kind>
    where
        Kind: 'a
, { ... }
fn is_kind(&self, kind: &Kind) -> bool
    where
        Kind: PartialEq
, { ... }
fn set_kind(&mut self, kind: Kind) -> &mut Self { ... }
fn take_kind(&mut self) -> Option<Kind> { ... }
fn delete_kind(&mut self) -> &mut Self { ... }
fn name<'a>(&'a self) -> Option<OneOrMany<&'a AnyString>>
    where
        Kind: 'a
, { ... }
fn set_name<T>(&mut self, name: T) -> &mut Self
    where
        T: Into<AnyString>
, { ... }
fn set_many_names<I, T>(&mut self, items: I) -> &mut Self
    where
        I: IntoIterator<Item = T>,
        T: Into<AnyString>
, { ... }
fn add_name<T>(&mut self, name: T) -> &mut Self
    where
        T: Into<AnyString>
, { ... }
fn take_name(&mut self) -> Option<OneOrMany<AnyString>> { ... }
fn delete_name(&mut self) -> &mut Self { ... }
fn media_type<'a>(&'a self) -> Option<&'a Mime>
    where
        Kind: 'a
, { ... }
fn set_media_type(&mut self, media_type: Mime) -> &mut Self { ... }
fn take_media_type(&mut self) -> Option<Mime> { ... }
fn delete_media_type(&mut self) -> &mut Self { ... }
fn preview<'a>(&'a self) -> Option<OneOrMany<&'a AnyBase>>
    where
        Kind: 'a
, { ... }
fn set_preview<T>(&mut self, preview: T) -> &mut Self
    where
        T: Into<AnyBase>
, { ... }
fn set_many_previews<I, T>(&mut self, items: I) -> &mut Self
    where
        I: IntoIterator<Item = T>,
        T: Into<AnyBase>
, { ... }
fn add_preview<T>(&mut self, preview: T) -> &mut Self
    where
        T: Into<AnyBase>
, { ... }
fn take_preview(&mut self) -> Option<OneOrMany<AnyBase>> { ... }
fn delete_preview(&mut self) -> &mut Self { ... } }

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, 

Fetch the context for the current object

use activitystreams_new::prelude::*;

let video_context = video.context();

fn set_context<T>(&mut self, context: T) -> &mut Self where
    T: Into<AnyBase>, 

Set the context for the current object

This overwrites the contents of context

use activitystreams_new::{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>, 

Set many contexts for the current object

This overwrites the contents of context

use activitystreams_new::{context, prelude::*, security};

video.set_many_contexts(vec![context(), security()]);

fn add_context<T>(&mut self, context: T) -> &mut Self where
    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_new::{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_new::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_new::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, 

Fetch the id for the current object, checking it against the provided domain

use activitystreams_new::prelude::*;

assert_eq!(video.id("example.com")?, Some(&uri!("https://example.com")));

fn id_unchecked<'a>(&'a self) -> Option<&'a Url> where
    Kind: 'a, 

Fetch the id for the current object

use activitystreams_new::prelude::*;

if let Some(id) = video.id_unchecked() {
    println!("{:?}", id);
}

fn id_mut<'a>(&'a mut self) -> Option<&'a mut Url> where
    Kind: 'a, 

Mutably borrow the ID from the current object

use activitystreams_new::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_new::{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_new::{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_new::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_new::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, 

Fetch the kind for the current object

use activitystreams_new::prelude::*;

if let Some(kind) = video.kind() {
    println!("{:?}", kind);
}

fn is_kind(&self, kind: &Kind) -> bool where
    Kind: PartialEq

Check if the provided Kind is equal to the object's Kind

use activitystreams_new::{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_new::prelude::*;

video.set_kind(VideoType::Video);

fn take_kind(&mut self) -> Option<Kind>

Take the kind from the current object, leaving nothing

use activitystreams_new::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_new::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, 

Fetch the name for the current object

use activitystreams_new::prelude::*;

if let Some(name) = video.name() {
    println!("{:?}", name);
}

fn set_name<T>(&mut self, name: T) -> &mut Self where
    T: Into<AnyString>, 

Set the name for the current object

This overwrites the contents of name

use activitystreams_new::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>, 

Set many names for the current object

This overwrites the contents of name

use activitystreams_new::prelude::*;
video.set_many_names(vec!["hi", "hey"]);

fn add_name<T>(&mut self, name: T) -> &mut Self where
    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_new::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_new::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_new::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, 

Fetch the media type for the current object

use activitystreams_new::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_new::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_new::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_new::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, 

Fetch the preview for the current object

use activitystreams_new::prelude::*;

if let Some(preview) = video.preview() {
    println!("{:?}", preview);
}

fn set_preview<T>(&mut self, preview: T) -> &mut Self where
    T: Into<AnyBase>, 

Set the preview for the current object

This overwrites the contents of preview

use activitystreams_new::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>, 

Set many previews for the current object

This overwrites the contents of preview

use activitystreams_new::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>, 

Add a preview to the current object

This does not overwrite the contents of preview, only appends an item

use activitystreams_new::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_new::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_new::prelude::*;

assert!(video.preview().is_some());
video.delete_preview();
assert!(video.preview().is_none());
Loading content...

Implementors

impl<T, Kind> BaseExt<Kind> for T where
    T: AsBase<Kind>, 
[src]

Loading content...