[][src]Struct activitystreams_new::primitives::AnyString

pub struct AnyString(_);

A type representing any kind of string

In the ActivityStreams specification, string types are often defined as either an xsd:String or and rdf:langString. The AnyString type represents this union.

Methods

impl AnyString[src]

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

Borrow the AnyString as an &str

let s_borrow = any_string
    .as_xsd_string()
    .ok_or(anyhow::Error::msg("Wrong string type"))?;

pub fn as_rdf_lang_string(&self) -> Option<&RdfLangString>[src]

Borrow the AnyString as an RdfLangString

let s_borrow = any_string
    .as_rdf_lang_string()
    .ok_or(anyhow::Error::msg("Wrong string type"))?;

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

Take the AnyString as a String

let xsd_string = any_string
    .xsd_string()
    .ok_or(anyhow::Error::msg("Wrong string type"))?;

pub fn rdf_lang_string(self) -> Option<RdfLangString>[src]

Take the AnyString as an RdfLangString

let rdf_lang_string = any_string
    .rdf_lang_string()
    .ok_or(anyhow::Error::msg("Wrong string type"))?;

pub fn from_xsd_string<T>(string: T) -> Self where
    T: Into<String>, 
[src]

Create a new AnyString from an Into<String>

use activitystreams_new::primitives::AnyString;

let any_string = AnyString::from_xsd_string("hi");

pub fn from_rdf_lang_string<T>(string: T) -> Self where
    T: Into<RdfLangString>, 
[src]

Create a new AnyString from an RdfLangString

use activitystreams_new::primitives::{AnyString, RdfLangString};

let any_string = AnyString::from_rdf_lang_string(RdfLangString {
    value: "hi".into(),
    language: "en".into(),
});

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

Replace the contents of self with a String

use activitystreams_new::primitives::{AnyString, RdfLangString};

let mut any_string = AnyString::from_rdf_lang_string(RdfLangString {
    value: "hi".into(),
    language: "en".into(),
});

any_string.set_xsd_string("hi");

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

pub fn set_rdf_lang_string<T>(&mut self, string: T) where
    T: Into<RdfLangString>, 
[src]

Replace the contents of self with an RdfLangString

use activitystreams_new::primitives::{AnyString, RdfLangString};

let mut any_string = AnyString::from_xsd_string("hi");

any_string.set_rdf_lang_string(RdfLangString {
    value: "hi".into(),
    language: "en".into(),
});

assert!(any_string.as_rdf_lang_string().is_some());

Trait Implementations

impl Clone for AnyString[src]

impl Debug for AnyString[src]

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

impl<'_> From<&'_ str> for AnyString[src]

impl From<RdfLangString> for AnyString[src]

impl From<String> for AnyString[src]

impl Serialize for AnyString[src]

Auto Trait Implementations

impl RefUnwindSafe for AnyString

impl Send for AnyString

impl Sync for AnyString

impl Unpin for AnyString

impl UnwindSafe for AnyString

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.