[][src]Struct activitystreams::base::Base

pub struct Base<Kind> { /* fields omitted */ }

A representation of the common fields between Links and Objects in ActivityStreams

Although the spec does not define a type more abstract that Object or Link, it does define fields present in both, so for the sake of "Everything derives from something," I've implemented a type.

Implementations

impl Base<Value>[src]

pub fn solidify<Kind>(self) -> Result<Base<Kind>, Error> where
    Kind: DeserializeOwned
[src]

Convert this Base<serde_json::Value> into a Base<Kind>

This is required before extending Base into the other types found in this crate

impl<Kind> Base<Kind>[src]

pub fn new() -> Self where
    Kind: Default
[src]

Create a new Base

use activitystreams::base::Base;

let base = Base::<String>::new();

pub fn extend<T>(self) -> Result<T, T::Error> where
    T: Extends<Kind>, 
[src]

Extend the Base into any other ActivityStreams type provided in this crate

let video = base.extend::<Video>()?;

pub fn retract<T>(t: T) -> Result<Self, T::Error> where
    T: Extends<Kind>, 
[src]

Retract any other ActivityStreams type into a Base<Kind>

let base = Base::retract(video)?;

pub fn into_generic(self) -> Result<Base<Value>, Error> where
    Kind: Serialize
[src]

Convert this Base into a Base<serde_json::Value>

This is required before putting a Base into an AnyBase type

pub fn map_kind<NewKind>(self, f: impl Fn(Kind) -> NewKind) -> Base<NewKind>[src]

An inffalible conversion from Base<T> to Base<U> where there is a known path from T to U

use activitystreams::{base::Base, prelude::*};

let mut base = Base::<String>::new();
base.set_kind("Hey".to_owned());

let new_base = base.map_kind(|kind| match kind.as_str() {
    "Create" => 1,
    "Update" => 5,
    _ => 0,
});

assert!(*new_base.kind().unwrap() == 0);

pub fn try_map_kind<NewKind, E>(
    self,
    f: impl Fn(Kind) -> Result<NewKind, E>
) -> Result<Base<NewKind>, E>
[src]

A fallible conversion from Base<T> to Base<U>

use activitystreams::{base::Base, prelude::*};

let mut base = Base::<String>::new();
base.set_kind("Hey".to_owned());

let new_base = base.try_map_kind(|kind| match kind.as_str() {
    "Create" => Ok(1),
    "Update" => Ok(5),
    _ => Err(anyhow::Error::msg("invalid kind")),
});

assert!(new_base.is_err());

Trait Implementations

impl<Kind> AsBase<Kind> for Base<Kind>[src]

impl<Kind> Base for Base<Kind>[src]

impl<Kind: Clone> Clone for Base<Kind>[src]

impl<Kind: Debug> Debug for Base<Kind>[src]

impl<'de, Kind> Deserialize<'de> for Base<Kind> where
    Kind: Deserialize<'de>, 
[src]

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

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

impl<Kind> Serialize for Base<Kind> where
    Kind: Serialize
[src]

impl<Kind> TryFrom<Base<Kind>> for Link<Kind> where
    Kind: DeserializeOwned
[src]

type Error = Error

The type returned in the event of a conversion error.

impl<Kind> TryFrom<Base<Kind>> for Object<Kind>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<Kind> TryFrom<Link<Kind>> for Base<Kind> where
    Kind: Serialize
[src]

type Error = Error

The type returned in the event of a conversion error.

impl<Kind> TryFrom<Object<Kind>> for Base<Kind>[src]

type Error = Error

The type returned in the event of a conversion error.

impl<Kind> UnparsedMut for Base<Kind>[src]

Auto Trait Implementations

impl<Kind> RefUnwindSafe for Base<Kind> where
    Kind: RefUnwindSafe

impl<Kind> Send for Base<Kind> where
    Kind: Send

impl<Kind> Sync for Base<Kind> where
    Kind: Sync

impl<Kind> Unpin for Base<Kind> where
    Kind: Unpin

impl<Kind> UnwindSafe for Base<Kind> where
    Kind: UnwindSafe

Blanket Implementations

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

impl<T, Kind> BaseExt<Kind> for T where
    T: AsBase<Kind>, 
[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.

impl<T> UnparsedMutExt for T where
    T: UnparsedMut
[src]