[][src]Struct activitystreams::base::AnyBase

pub struct AnyBase(_);

A type that can represent Any ActivityStreams type

A type in activitystreams can be four things

  • An Object
  • A Link
  • The ID of that Link or Object
  • A string representing that Link or Object

Implementations

impl AnyBase[src]

pub fn from_extended<T, Kind>(extended: T) -> Result<Self, T::Error> where
    T: Extends<Kind>,
    T::Error: From<Error>,
    Kind: Serialize
[src]

Convert any type that is extended from Base<Kind> into an AnyBase for storing

let any_base = AnyBase::from_extended(video)?;

pub fn is_xsd_any_uri(&self) -> bool[src]

Check if this object is a Url

let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));
assert!(any_base.is_xsd_any_uri());

pub fn is_xsd_string(&self) -> bool[src]

Check if this object is a String

let any_base = AnyBase::from_xsd_string("Profile".into());
assert!(any_base.is_xsd_string());

pub fn is_base(&self) -> bool[src]

Check if this object is a Base<serde_json::Value>

let any_base = AnyBase::from_extended(video)?;
assert!(any_base.is_base());

pub fn id(&self) -> Option<&Url>[src]

Get the id from the current object

This method checks if the current object is an ID, and then falls back on the id field within the Base<serde_json::Value> if that exists

Get the ID from the nested video

let id = uri!("https://example.com");

video.set_id(id.clone());

let any_base = AnyBase::from_extended(video)?;
assert!(any_base.id().unwrap() == &id);

Get the ID from the AnyBase

let id = uri!("https://example.com");

let any_base = AnyBase::from_xsd_any_uri(id.clone());
assert!(any_base.id().unwrap() == &id);

pub fn is_id(&self, id: &Url) -> bool[src]

Check if the current object's id matches the provided id

video.set_id(uri!("https://example.com"));

let any_base = AnyBase::from_extended(video)?;

assert!(any_base.is_id(&uri!("https://example.com")));

pub fn kind(&self) -> Option<&Value>[src]

Get the kind from the current object

This method only produces a value if the current object is a Base<serde_json::Value>

video.set_kind(VideoType::Video);

let any_base = AnyBase::from_extended(video)?;

match any_base.kind().and_then(|k| k.as_str()) {
    Some("Video") => println!("yay!"),
    _ => return Err(anyhow::Error::msg("invalid type found")),
}

pub fn kind_str(&self) -> Option<&str>[src]

Get the kind from the current object as an &str

This method only produces a value if the current object is a Base<serde_json::Value>, and the kind is present, and a string

video.set_kind(VideoType::Video);

let any_base = AnyBase::from_extended(video)?;

match any_base.kind_str() {
    Some("Video") => println!("yay!"),
    _ => return Err(anyhow::Error::msg("invalid type found")),
}

pub fn is_kind(&self, kind: &str) -> bool[src]

Check if the current object's kind matches the provided kind

video.set_kind(VideoType::Video);

let any_base = AnyBase::from_extended(video)?;

assert!(any_base.is_kind("Video"));

pub fn as_xsd_any_uri(&self) -> Option<&Url>[src]

Get the object as a Url

let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));

assert!(any_base.as_xsd_any_uri().is_some());

pub fn as_xsd_string(&self) -> Option<&str>[src]

Get the object as an &str

let any_base = AnyBase::from_xsd_string("hi".into());

assert!(any_base.as_xsd_string().is_some());

pub fn as_base(&self) -> Option<&Base<Value>>[src]

Get the object as a Base<serde_json::Value>

let any_base = AnyBase::from_extended(video)?;

assert!(any_base.as_base().is_some());

pub fn take_xsd_any_uri(self) -> Option<Url>[src]

Take the Url from the Object

let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));

assert!(any_base.take_xsd_any_uri().is_some());

pub fn take_xsd_string(self) -> Option<String>[src]

Take the String from the Object

let any_base = AnyBase::from_xsd_string("hi".into());

assert!(any_base.take_xsd_string().is_some());

pub fn take_base(self) -> Option<Base<Value>>[src]

Take the Base<serde_json::Value> from the Object

let any_base = AnyBase::from_extended(video)?;

assert!(any_base.take_base().is_some());

pub fn set_xsd_any_uri(&mut self, id: Url)[src]

Replace the object with the provided Url

let mut any_base = AnyBase::from_xsd_string("hi".into());

any_base.set_xsd_any_uri(uri!("https://example.com"));

assert!(any_base.take_xsd_any_uri().is_some());

pub fn set_xsd_string<T>(&mut self, xsd_string: T) where
    T: Into<String>, 
[src]

Replace the object with the provided String

let mut any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));

any_base.set_xsd_string("hi");

assert!(any_base.take_xsd_string().is_some());

pub fn set_base(&mut self, base: Base<Value>)[src]

Replace the object with the provided Base<serde_json::Value>

let mut any_base = AnyBase::from_xsd_string("hi".into());

let base = Base::retract(video)?.into_generic()?;
any_base.set_base(base);

assert!(any_base.take_base().is_some());

pub fn from_xsd_any_uri(id: Url) -> Self[src]

Create an AnyBase from a Url

use activitystreams::{base::AnyBase, uri};
let any_base = AnyBase::from_xsd_any_uri(uri!("https://example.com"));

pub fn from_xsd_string(xsd_string: String) -> Self[src]

Create an AnyBase from an String

use activitystreams::base::AnyBase;
let any_base = AnyBase::from_xsd_string("hi".into());

pub fn from_base(base: Base<Value>) -> Self[src]

Create an AnyBase from a Base<serde_json::Value>

use activitystreams::base::{AnyBase, Base};

let base = Base::retract(video)?.into_generic()?;
let any_base = AnyBase::from_base(base);

Trait Implementations

impl Clone for AnyBase[src]

impl Debug for AnyBase[src]

impl<'de> Deserialize<'de> for AnyBase[src]

impl From<Base<Value>> for AnyBase[src]

impl From<String> for AnyBase[src]

impl From<Url> for AnyBase[src]

impl Serialize for AnyBase[src]

Auto Trait Implementations

impl RefUnwindSafe for AnyBase

impl Send for AnyBase

impl Sync for AnyBase

impl Unpin for AnyBase

impl UnwindSafe for AnyBase

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.