XsdString - gone

This commit is contained in:
asonix 2020-06-03 12:31:54 -05:00
parent 2cb0ee89d1
commit d37714ff57
8 changed files with 148 additions and 146 deletions

View file

@ -2,7 +2,7 @@ use activitystreams_new::{
context,
object::{ApObject, Video},
prelude::*,
primitives::{XsdAnyUri, XsdString},
primitives::XsdAnyUri,
};
fn main() -> Result<(), anyhow::Error> {
@ -13,7 +13,7 @@ fn main() -> Result<(), anyhow::Error> {
.set_id("https://example.com/@example/lions".parse()?)
.set_media_type("video/webm".parse()?)
.set_url("https://example.com/@example/lions/video.webm".parse::<XsdAnyUri>()?)
.set_summary(XsdString::from("A cool video"))
.set_summary("A cool video".to_owned())
.set_duration("PT4M20S".parse()?)
.set_shares("https://example.com/@example/lions/video.webm#shares".parse()?);

View file

@ -25,7 +25,7 @@ use crate::{
base::{AsBase, Base, Extends},
markers,
object::{ApObject, AsApObject, AsObject, Object},
primitives::{OneOrMany, XsdAnyUri, XsdString},
primitives::{OneOrMany, XsdAnyUri},
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
};
use typed_builder::TypedBuilder;
@ -500,11 +500,14 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// println!("{:?}", preferred_username);
/// }
/// ```
fn preferred_username<'a>(&'a self) -> Option<&'a XsdString>
fn preferred_username<'a>(&'a self) -> Option<&'a str>
where
Inner: 'a,
{
self.ap_actor_ref().preferred_username.as_ref()
self.ap_actor_ref()
.preferred_username
.as_ref()
.map(|pu| pu.as_str())
}
/// Set the preferred_username for the current actor
@ -519,7 +522,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// # Ok(())
/// # }
/// ```
fn set_preferred_username(&mut self, string: XsdString) -> &mut Self {
fn set_preferred_username(&mut self, string: String) -> &mut Self {
self.ap_actor_mut().preferred_username = Some(string);
self
}
@ -535,7 +538,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// println!("{:?}", preferred_username);
/// }
/// ```
fn take_preferred_username(&mut self) -> Option<XsdString> {
fn take_preferred_username(&mut self) -> Option<String> {
self.ap_actor_mut().preferred_username.take()
}
@ -730,7 +733,7 @@ pub struct ApActor<Inner> {
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
pub preferred_username: Option<XsdString>,
pub preferred_username: Option<String>,
/// A json object which maps additional (typically server/domain-wide) endpoints which may be
/// useful either for this actor or someone referencing this actor.

View file

@ -7,7 +7,6 @@
//! context,
//! object::Video,
//! prelude::*,
//! primitives::XsdString,
//! security,
//! };
//! let mut video = Video::new();
@ -16,7 +15,7 @@
//! .set_id("https://example.com".parse()?)
//! .set_context(context())
//! .add_context(security())
//! .set_name(XsdString::from("Hello"));
//! .set_name("Hello".to_owned());
//!
//! let any_base = video.into_any_base()?;
//!
@ -30,7 +29,7 @@
use crate::{
either::Either,
markers,
primitives::{AnyString, MimeMediaType, OneOrMany, XsdAnyUri, XsdString},
primitives::{AnyString, MimeMediaType, OneOrMany, XsdAnyUri},
unparsed::{Unparsed, UnparsedMut},
};
use typed_builder::TypedBuilder;
@ -247,7 +246,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// Fetch the id for the current object
///
/// ```rust
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// use activitystreams_new::prelude::*;
@ -285,7 +284,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// use activitystreams_new::prelude::*;
@ -302,7 +301,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// Take the id from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// use activitystreams_new::prelude::*;
@ -336,7 +335,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// Fetch the kind for the current object
///
/// ```rust
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// use activitystreams_new::prelude::*;
@ -396,7 +395,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// Take the kind from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// use activitystreams_new::prelude::*;
@ -430,7 +429,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// Fetch the name for the current object
///
/// ```
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// use activitystreams_new::prelude::*;
@ -452,10 +451,10 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
///
/// ```rust
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// video.set_name(XsdString::from("hi"));
/// video.set_name("hi".to_owned());
/// ```
fn set_name<T>(&mut self, name: T) -> &mut Self
where
@ -471,10 +470,10 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
///
/// ```rust
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// video.set_many_names(vec![XsdString::from("hi"), XsdString::from("hey")]);
/// video.set_many_names(vec!["hi".to_owned(), "hey".to_owned()]);
/// ```
fn set_many_names<I, T>(&mut self, items: I) -> &mut Self
where
@ -492,12 +491,12 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
///
/// ```rust
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// video
/// .add_name(XsdString::from("hi"))
/// .add_name(XsdString::from("hey"));
/// .add_name("hi".to_owned())
/// .add_name("hey".to_owned());
/// ```
fn add_name<T>(&mut self, name: T) -> &mut Self
where
@ -534,9 +533,9 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
///
/// ```rust
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// # video.set_name(XsdString::from("hi"));
/// # video.set_name("hi".to_owned());
/// #
///
/// assert!(video.name().is_some());
@ -773,7 +772,7 @@ struct IdOrBase(Either<XsdAnyUri, Box<Base<serde_json::Value>>>);
/// - A string representing that Link or Object
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(transparent)]
pub struct AnyBase(Either<IdOrBase, XsdString>);
pub struct AnyBase(Either<IdOrBase, String>);
/// A representation of the common fields between Links and Objects in ActivityStreams
///
@ -1056,7 +1055,7 @@ impl AnyBase {
.is_some()
}
/// Check if this object is an XsdString
/// Check if this object is a String
///
/// ```rust
/// # use activitystreams_new::base::AnyBase;
@ -1237,7 +1236,7 @@ impl AnyBase {
self.0.as_ref().left().and_then(|l| l.as_xsd_any_uri())
}
/// Get the object as an XsdString
/// Get the object as an &str
///
/// ```rust
/// # use activitystreams_new::base::AnyBase;
@ -1246,8 +1245,8 @@ impl AnyBase {
///
/// assert!(any_base.as_xsd_string().is_some());
/// ```
pub fn as_xsd_string(&self) -> Option<&XsdString> {
self.0.as_ref().right()
pub fn as_xsd_string(&self) -> Option<&str> {
self.0.as_ref().right().map(|r| r.as_str())
}
/// Get the object as a `Base<serde_json::Value>`
@ -1285,7 +1284,7 @@ impl AnyBase {
self.0.left().and_then(|l| l.id())
}
/// Take the XsdString from the Object
/// Take the String from the Object
///
/// ```rust
/// # use activitystreams_new::base::AnyBase;
@ -1294,7 +1293,7 @@ impl AnyBase {
///
/// assert!(any_base.take_xsd_string().is_some());
/// ```
pub fn take_xsd_string(self) -> Option<XsdString> {
pub fn take_xsd_string(self) -> Option<String> {
self.0.right()
}
@ -1335,7 +1334,7 @@ impl AnyBase {
self.0 = Either::Left(IdOrBase::from_xsd_any_uri(id));
}
/// Replace the object with the provided XsdString
/// Replace the object with the provided String
///
/// ```
/// # fn main() -> Result<(), anyhow::Error> {
@ -1350,7 +1349,7 @@ impl AnyBase {
/// # Ok(())
/// # }
/// ```
pub fn set_xsd_string(&mut self, xsd_string: XsdString) {
pub fn set_xsd_string(&mut self, xsd_string: String) {
self.0 = Either::Right(xsd_string);
}
@ -1387,13 +1386,13 @@ impl AnyBase {
AnyBase(Either::Left(IdOrBase::from_xsd_any_uri(id)))
}
/// Create an AnyBase from an XsdString
/// Create an AnyBase from an String
///
/// ```rust
/// use activitystreams_new::base::AnyBase;
/// let any_base = AnyBase::from_xsd_string("hi".into());
/// ```
pub fn from_xsd_string(xsd_string: XsdString) -> Self {
pub fn from_xsd_string(xsd_string: String) -> Self {
AnyBase(Either::Right(xsd_string))
}
@ -1534,7 +1533,7 @@ impl OneOrMany<AnyBase> {
self.as_one().and_then(|inner| inner.as_xsd_any_uri())
}
/// Get a single XsdString from the object, if that is what is contained
/// Get a single &str from the object, if that is what is contained
///
/// ```rust
/// # use activitystreams_new::{base::AnyBase, primitives::OneOrMany};
@ -1543,7 +1542,7 @@ impl OneOrMany<AnyBase> {
///
/// assert!(one.as_single_xsd_string().is_some());
/// ```
pub fn as_single_xsd_string(&self) -> Option<&XsdString> {
pub fn as_single_xsd_string(&self) -> Option<&str> {
self.as_one().and_then(|inner| inner.as_xsd_string())
}
@ -1578,7 +1577,7 @@ impl OneOrMany<AnyBase> {
self.one().and_then(|inner| inner.take_xsd_any_uri())
}
/// Take a single XsdString from the object, if that is what is contained
/// Take a single String from the object, if that is what is contained
///
/// ```rust
/// # use activitystreams_new::{base::AnyBase, primitives::OneOrMany};
@ -1587,7 +1586,7 @@ impl OneOrMany<AnyBase> {
///
/// assert!(one.single_xsd_string().is_some());
/// ```
pub fn single_xsd_string(self) -> Option<XsdString> {
pub fn single_xsd_string(self) -> Option<String> {
self.one().and_then(|inner| inner.take_xsd_string())
}
@ -1619,14 +1618,14 @@ impl OneOrMany<AnyBase> {
OneOrMany(Either::Left(AnyBase::from_xsd_any_uri(id)))
}
/// Create a `OneOrMany<AnyBase>` from an XsdString
/// Create a `OneOrMany<AnyBase>` from a String
///
/// ```rust
/// use activitystreams_new::{base::AnyBase, primitives::OneOrMany};
///
/// let one = OneOrMany::<AnyBase>::from_xsd_string("hi".into());
/// ```
pub fn from_xsd_string(xsd_string: XsdString) -> Self {
pub fn from_xsd_string(xsd_string: String) -> Self {
OneOrMany(Either::Left(AnyBase::from_xsd_string(xsd_string)))
}
@ -1661,7 +1660,7 @@ impl OneOrMany<AnyBase> {
self
}
/// Overwrite the current object with an XsdString
/// Overwrite the current object with a String
///
/// ```rust
/// # use activitystreams_new::{base::Base, primitives::OneOrMany};
@ -1673,7 +1672,7 @@ impl OneOrMany<AnyBase> {
///
/// assert!(one.as_single_xsd_string().is_some());
/// ```
pub fn set_single_xsd_string(&mut self, xsd_string: XsdString) -> &mut Self {
pub fn set_single_xsd_string(&mut self, xsd_string: String) -> &mut Self {
self.0 = Either::Left(AnyBase::from_xsd_string(xsd_string));
self
}
@ -1709,7 +1708,7 @@ impl OneOrMany<AnyBase> {
self.add(AnyBase::from_xsd_any_uri(id))
}
/// Append an XsdString to the current object
/// Append a String to the current object
///
/// ```rust
/// use activitystreams_new::{context, primitives::OneOrMany};
@ -1719,7 +1718,7 @@ impl OneOrMany<AnyBase> {
/// many.add_xsd_string("hi".into())
/// .add_xsd_string("hello".into());
/// ```
pub fn add_xsd_string(&mut self, xsd_string: XsdString) -> &mut Self {
pub fn add_xsd_string(&mut self, xsd_string: String) -> &mut Self {
self.add(AnyBase::from_xsd_string(xsd_string))
}
@ -1778,8 +1777,8 @@ impl From<XsdAnyUri> for AnyBase {
}
}
impl From<XsdString> for AnyBase {
fn from(xsd_string: XsdString) -> Self {
impl From<String> for AnyBase {
fn from(xsd_string: String) -> Self {
Self::from_xsd_string(xsd_string)
}
}
@ -1796,8 +1795,8 @@ impl From<XsdAnyUri> for OneOrMany<AnyBase> {
}
}
impl From<XsdString> for OneOrMany<AnyBase> {
fn from(xsd_string: XsdString) -> Self {
impl From<String> for OneOrMany<AnyBase> {
fn from(xsd_string: String) -> Self {
Self::from_xsd_string(xsd_string)
}
}

View file

@ -92,10 +92,10 @@
//! fn from_xsd_string<T>(&mut self, T) -> Self;
//! fn from_rdf_lang_string<T>(&mut self, T) -> Self;
//!
//! fn as_single_xsd_string(&self) -> Option<&XsdString>;
//! fn as_single_xsd_string(&self) -> Option<&str>;
//! fn as_single_rdf_langstring(&self) -> Option<&RdfLangString>;
//!
//! fn single_xsd_string(self) -> Option<XsdString>;
//! fn single_xsd_string(self) -> Option<String>;
//! fn single_rdf_lang_string(self) -> Option<RdfLangString>;
//!
//! fn add_xsd_string<T>(&mut self, T) -> &mut Self;
@ -103,10 +103,10 @@
//! ```
//! These methods provide access to setting and fetching uniformly typed data, as well as deleting
//! the data. In the setter methods, the type parameter T is bound by
//! `Into<XsdString>` or `Into<RdfLangString>`. This allows passing values to the method that
//! `Into<String>` or `Into<RdfLangString>`. This allows passing values to the method that
//! can be converted into the types, rather than requiring the caller to perform the conversion.
//!
//! Types like `XsdString` and `RdfLangString` can be found in the `primitives` module. Unless
//! Types like `RdfLangString` can be found in the `primitives` module. Unless
//! you're building your own custom types, you shouldn't need to import them yourself. They each
//! implement `FromStr` for parsing and `Display` to convert back to strings, as well as `From` and
//! `Into` or `TryFrom` and `TryInto` for types you might expect them to (e.g.
@ -205,7 +205,7 @@
//! context,
//! object::{ApObject, Video},
//! prelude::*,
//! primitives::{XsdAnyUri, XsdString},
//! primitives::XsdAnyUri,
//! };
//!
//! fn main() -> Result<(), anyhow::Error> {
@ -216,7 +216,7 @@
//! .set_id("https://example.com/@example/lions".parse()?)
//! .set_media_type("video/webm".parse()?)
//! .set_url("https://example.com/@example/lions/video.webm".parse::<XsdAnyUri>()?)
//! .set_summary(XsdString::from("A cool video"))
//! .set_summary("A cool video".to_owned())
//! .set_duration("PT4M20S".parse()?)
//! .set_shares("https://example.com/@example/lions/video.webm#shares".parse()?);
//!
@ -308,14 +308,14 @@ pub mod markers {
//! Marker traits for bounding methods
//!
//! ```rust
//! use activitystreams_new::{base::BaseExt, markers::Activity, primitives::XsdString};
//! use activitystreams_new::{base::BaseExt, markers::Activity};
//!
//! /// Applies the name "hi" to any given activity
//! fn manipulator<T, Kind>(mut some_type: T) -> T
//! where
//! T: Activity + BaseExt<Kind>,
//! {
//! some_type.set_name(XsdString::from("hi"));
//! some_type.set_name("hi".to_owned());
//!
//! some_type
//! }
@ -336,7 +336,7 @@ pub mod prelude {
//! actor::{kind::PersonType, ApActor, Person},
//! context,
//! prelude::*,
//! primitives::{XsdAnyUri, XsdString},
//! primitives::XsdAnyUri,
//! public,
//! object::{
//! kind::{ImageType, VideoType},
@ -351,8 +351,8 @@ pub mod prelude {
//! );
//! person
//! .set_outbox("http:/localhost:8080/outbox".parse()?)
//! .set_name(XsdString::from("Demo Account"))
//! .set_preferred_username(XsdString::from("demo"))
//! .set_name("Demo Account".to_owned())
//! .set_preferred_username("demo".to_owned())
//! .set_id("https://localhost:8080/actor".parse()?)
//! .set_url("https://localhost:8080/actor".parse::<XsdAnyUri>()?);
//!
@ -369,7 +369,7 @@ pub mod prelude {
//! .set_id("http://localhost:8080/video.webm".parse()?)
//! .set_url("http://localhost:8080/video.webm".parse::<XsdAnyUri>()?)
//! .set_media_type("video/webm".parse()?)
//! .set_summary(XsdString::from("A cool video"))
//! .set_summary("A cool video".to_owned())
//! .set_preview(preview.into_any_base()?)
//! .set_duration("PT4M20S".parse()?)
//! .set_shares("http://localhost:8080/video.webm#shares".parse()?);

View file

@ -23,7 +23,7 @@
use crate::{
base::{AsBase, Base, Extends},
markers,
primitives::{OneOrMany, XsdAnyUri, XsdNonNegativeInteger, XsdString},
primitives::{OneOrMany, XsdAnyUri, XsdNonNegativeInteger},
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
};
use std::convert::TryFrom;
@ -141,11 +141,11 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
///
/// let mention_hreflang = mention.hreflang();
/// ```
fn hreflang<'a>(&'a self) -> Option<&'a XsdString>
fn hreflang<'a>(&'a self) -> Option<&'a str>
where
Kind: 'a,
{
self.link_ref().hreflang.as_ref()
self.link_ref().hreflang.as_ref().map(|lr| lr.as_str())
}
/// Set the hreflang for the current object
@ -160,7 +160,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
///
/// mention.set_hreflang("en".into());
/// ```
fn set_hreflang(&mut self, hreflang: XsdString) -> &mut Self {
fn set_hreflang(&mut self, hreflang: String) -> &mut Self {
self.link_mut().hreflang = Some(hreflang);
self
}
@ -177,7 +177,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// println!("{:?}", hreflang);
/// }
/// ```
fn take_hreflang(&mut self) -> Option<XsdString> {
fn take_hreflang(&mut self) -> Option<String> {
self.link_mut().hreflang.take()
}
@ -212,7 +212,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
///
/// let mention_rel = mention.rel();
/// ```
fn rel<'a>(&'a self) -> Option<&'a OneOrMany<XsdString>>
fn rel<'a>(&'a self) -> Option<&'a OneOrMany<String>>
where
Kind: 'a,
{
@ -231,7 +231,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
///
/// mention.set_rel("link".into());
/// ```
fn set_rel(&mut self, rel: XsdString) -> &mut Self {
fn set_rel(&mut self, rel: String) -> &mut Self {
self.link_mut().rel = Some(rel.into());
self
}
@ -250,7 +250,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// ```
fn set_many_rels<I>(&mut self, items: I) -> &mut Self
where
I: IntoIterator<Item = XsdString>,
I: IntoIterator<Item = String>,
{
let v: Vec<_> = items.into_iter().collect();
self.link_mut().rel = Some(v.into());
@ -271,7 +271,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// .add_rel("link".into())
/// .add_rel("stylesheet".into());
/// ```
fn add_rel(&mut self, rel: XsdString) -> &mut Self {
fn add_rel(&mut self, rel: String) -> &mut Self {
let v = match self.link_mut().rel.take() {
Some(mut v) => {
v.add(rel);
@ -295,7 +295,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// println!("{:?}", rel);
/// }
/// ```
fn take_rel(&mut self) -> Option<OneOrMany<XsdString>> {
fn take_rel(&mut self) -> Option<OneOrMany<String>> {
self.link_mut().rel.take()
}
@ -505,7 +505,7 @@ pub struct Link<Kind> {
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
pub hreflang: Option<XsdString>,
pub hreflang: Option<String>,
/// A link relation associated with a Link.
///
@ -517,7 +517,7 @@ pub struct Link<Kind> {
/// - Functional: false
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub rel: Option<OneOrMany<XsdString>>,
pub rel: Option<OneOrMany<String>>,
/// On a Link, specifies a hint as to the rendering height in device-independent pixels of the linked resource.
///

View file

@ -543,10 +543,10 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
///
/// ```rust
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
///
/// video.set_content(XsdString::from("hi"));
/// video.set_content("hi".to_owned());
/// ```
fn set_content<T>(&mut self, content: T) -> &mut Self
where
@ -562,12 +562,12 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
///
/// ```rust
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
///
/// video.set_many_contents(vec![
/// XsdString::from("hi"),
/// "hello".into(),
/// "hi".to_owned(),
/// "hello".to_owned(),
/// ]);
/// ```
fn set_many_contents<I, T>(&mut self, items: I) -> &mut Self
@ -586,12 +586,12 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
///
/// ```rust
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
///
/// video
/// .add_content(XsdString::from("hi"))
/// .add_content(XsdString::from("hello"));
/// .add_content("hi".to_owned())
/// .add_content("hello".to_owned());
/// ```
fn add_content<T>(&mut self, content: T) -> &mut Self
where
@ -627,9 +627,9 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// Delete the content from the current object
///
/// ```rust
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// # video.set_content(XsdString::from("https://example.com"));
/// # video.set_content("content".to_owned());
/// #
/// use activitystreams_new::prelude::*;
///
@ -667,10 +667,10 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
///
/// ```rust
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
///
/// video.set_summary(XsdString::from("hi"));
/// video.set_summary("hi".to_owned());
/// ```
fn set_summary<T>(&mut self, summary: T) -> &mut Self
where
@ -686,12 +686,12 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
///
/// ```rust
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
///
/// video.set_many_summaries(vec![
/// XsdString::from("hi"),
/// "hello".into(),
/// "hi".to_owned(),
/// "hello".to_owned(),
/// ]);
/// ```
fn set_many_summaries<I, T>(&mut self, items: I) -> &mut Self
@ -710,12 +710,12 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
///
/// ```rust
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
///
/// video
/// .add_summary(XsdString::from("hi"))
/// .add_summary(XsdString::from("hello"));
/// .add_summary("hi".to_owned())
/// .add_summary("hello".to_owned());
/// ```
fn add_summary<T>(&mut self, summary: T) -> &mut Self
where
@ -751,9 +751,9 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// Delete the summary from the current object
///
/// ```rust
/// # use activitystreams_new::{object::Video, primitives::XsdString};
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// # video.set_summary(XsdString::from("https://example.com"));
/// # video.set_summary("summary".to_owned());
/// #
/// use activitystreams_new::prelude::*;
///
@ -2783,7 +2783,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// Fetch the shares for the current object
///
/// ```rust
/// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString};
/// # use activitystreams_new::object::{ApObject, Video};
/// # let mut video = ApObject::new(Video::new());
/// #
/// use activitystreams_new::prelude::*;
@ -2805,7 +2805,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString};
/// # use activitystreams_new::object::{ApObject, Video};
/// # let mut video = ApObject::new(Video::new());
/// #
/// use activitystreams_new::prelude::*;
@ -2822,7 +2822,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// Take the shares from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString};
/// # use activitystreams_new::object::{ApObject, Video};
/// # let mut video = ApObject::new(Video::new());
/// #
/// use activitystreams_new::prelude::*;
@ -2856,7 +2856,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// Fetch the likes for the current object
///
/// ```rust
/// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString};
/// # use activitystreams_new::object::{ApObject, Video};
/// # let mut video = ApObject::new(Video::new());
/// #
/// use activitystreams_new::prelude::*;
@ -2878,7 +2878,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString};
/// # use activitystreams_new::object::{ApObject, Video};
/// # let mut video = ApObject::new(Video::new());
/// #
/// use activitystreams_new::prelude::*;
@ -2895,7 +2895,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// Take the likes from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString};
/// # use activitystreams_new::object::{ApObject, Video};
/// # let mut video = ApObject::new(Video::new());
/// #
/// use activitystreams_new::prelude::*;
@ -2929,7 +2929,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// Fetch the source for the current object
///
/// ```rust
/// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString};
/// # use activitystreams_new::object::{ApObject, Video};
/// # let mut video = ApObject::new(Video::new());
/// #
/// use activitystreams_new::prelude::*;
@ -2971,7 +2971,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// Take the source from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString};
/// # use activitystreams_new::object::{ApObject, Video};
/// # let mut video = ApObject::new(Video::new());
/// #
/// use activitystreams_new::prelude::*;
@ -3005,7 +3005,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// Fetch the upload_media for the current object
///
/// ```rust
/// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString};
/// # use activitystreams_new::object::{ApObject, Video};
/// # let mut video = ApObject::new(Video::new());
/// #
/// use activitystreams_new::prelude::*;
@ -3100,7 +3100,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// Take the upload_media from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString};
/// # use activitystreams_new::object::{ApObject, Video};
/// # let mut video = ApObject::new(Video::new());
/// #
/// use activitystreams_new::prelude::*;
@ -3568,7 +3568,7 @@ pub trait ProfileExt: AsProfile {
/// Fetch the described object for the current object
///
/// ```rust
/// # use activitystreams_new::{object::Profile, primitives::XsdString};
/// # use activitystreams_new::object::Profile;
/// # let mut profile = Profile::new();
/// #
/// use activitystreams_new::prelude::*;
@ -3607,7 +3607,7 @@ pub trait ProfileExt: AsProfile {
/// Take the described object from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{object::Profile, primitives::XsdString};
/// # use activitystreams_new::object::Profile;
/// # let mut profile = Profile::new();
/// #
/// use activitystreams_new::prelude::*;
@ -3648,7 +3648,7 @@ pub trait RelationshipExt: AsRelationship {
/// Fetch the subject for the current object
///
/// ```rust
/// # use activitystreams_new::{object::Relationship, primitives::XsdString};
/// # use activitystreams_new::object::Relationship;
/// # let mut relationship = Relationship::new();
/// #
/// use activitystreams_new::prelude::*;
@ -3687,7 +3687,7 @@ pub trait RelationshipExt: AsRelationship {
/// Take the subject from the current object, leaving nothing
///
/// ```rust
/// # use activitystreams_new::{object::Relationship, primitives::XsdString};
/// # use activitystreams_new::object::Relationship;
/// # let mut relationship = Relationship::new();
/// #
/// use activitystreams_new::prelude::*;

View file

@ -17,7 +17,7 @@ use crate::either::Either;
pub use activitystreams::primitives::{
MimeMediaType, MimeMediaTypeError, RdfLangString, XsdAnyUri, XsdAnyUriError, XsdDateTime,
XsdDateTimeError, XsdDuration, XsdDurationError, XsdFloat, XsdFloatError,
XsdNonNegativeInteger, XsdString,
XsdNonNegativeInteger,
};
use activitystreams::primitives::Length;
@ -28,7 +28,7 @@ use activitystreams::primitives::Length;
/// and rdf:langString. The AnyString type represents this union.
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(transparent)]
pub struct AnyString(Either<XsdString, RdfLangString>);
pub struct AnyString(Either<String, RdfLangString>);
/// A type representing units of length
///
@ -43,7 +43,7 @@ pub struct AnyString(Either<XsdString, RdfLangString>);
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
)]
#[serde(transparent)]
pub struct Unit(Either<Length, XsdString>);
pub struct Unit(Either<Length, String>);
/// A type representing at least one value
///
@ -68,7 +68,7 @@ pub struct Unit(Either<Length, XsdString>);
pub struct OneOrMany<T>(pub(crate) Either<T, Vec<T>>);
impl AnyString {
/// Borrow the AnyString as an XsdString
/// Borrow the AnyString as an &str
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
@ -81,8 +81,8 @@ impl AnyString {
/// # Ok(())
/// # }
/// ```
pub fn as_xsd_string(&self) -> Option<&XsdString> {
self.0.as_ref().left()
pub fn as_xsd_string(&self) -> Option<&str> {
self.0.as_ref().left().map(|l| l.as_str())
}
/// Borrow the AnyString as an RdfLangString
@ -105,7 +105,7 @@ impl AnyString {
self.0.as_ref().right()
}
/// Take the AnyString as an XsdString
/// Take the AnyString as a String
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
@ -118,7 +118,7 @@ impl AnyString {
/// # Ok(())
/// # }
/// ```
pub fn xsd_string(self) -> Option<XsdString> {
pub fn xsd_string(self) -> Option<String> {
self.0.left()
}
@ -142,7 +142,7 @@ impl AnyString {
self.0.right()
}
/// Create a new AnyString from an `Into<XsdString>`
/// Create a new AnyString from an `Into<String>`
///
/// ```rust
/// use activitystreams_new::primitives::AnyString;
@ -151,7 +151,7 @@ impl AnyString {
/// ```
pub fn from_xsd_string<T>(string: T) -> Self
where
T: Into<XsdString>,
T: Into<String>,
{
AnyString(Either::Left(string.into()))
}
@ -173,7 +173,7 @@ impl AnyString {
AnyString(Either::Right(string.into()))
}
/// Replace the contents of self with an XsdString
/// Replace the contents of self with a String
///
/// ```rust
/// use activitystreams_new::primitives::{AnyString, RdfLangString};
@ -189,7 +189,7 @@ impl AnyString {
/// ```
pub fn set_xsd_string<T>(&mut self, string: T)
where
T: Into<XsdString>,
T: Into<String>,
{
self.0 = Either::Left(string.into());
}
@ -217,7 +217,7 @@ impl AnyString {
}
impl OneOrMany<AnyString> {
/// Try to borrow a single XsdString from the current object
/// Try to borrow a single String from the current object
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
@ -229,7 +229,7 @@ impl OneOrMany<AnyString> {
/// # Ok(())
/// # }
/// ```
pub fn as_single_xsd_string(&self) -> Option<&XsdString> {
pub fn as_single_xsd_string(&self) -> Option<&str> {
self.as_one()
.and_then(|any_string| any_string.as_xsd_string())
}
@ -254,7 +254,7 @@ impl OneOrMany<AnyString> {
.and_then(|any_string| any_string.as_rdf_lang_string())
}
/// Try to take a single XsdString from the current object
/// Try to take a single String from the current object
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
@ -266,7 +266,7 @@ impl OneOrMany<AnyString> {
/// # Ok(())
/// # }
/// ```
pub fn single_xsd_string(self) -> Option<XsdString> {
pub fn single_xsd_string(self) -> Option<String> {
self.one().and_then(|any_string| any_string.xsd_string())
}
@ -290,7 +290,7 @@ impl OneOrMany<AnyString> {
.and_then(|any_string| any_string.rdf_lang_string())
}
/// Create the object from a single XsdString
/// Create the object from a single String
///
/// ```rust
/// use activitystreams_new::primitives::{OneOrMany, AnyString};
@ -299,7 +299,7 @@ impl OneOrMany<AnyString> {
/// ```
pub fn from_xsd_string<T>(string: T) -> Self
where
T: Into<XsdString>,
T: Into<String>,
{
Self::from_one(AnyString::from_xsd_string(string))
}
@ -321,7 +321,7 @@ impl OneOrMany<AnyString> {
Self::from_one(AnyString::from_rdf_lang_string(string))
}
/// Add an XsdString to the object, appending to whatever is currently included
/// Add a String to the object, appending to whatever is currently included
///
/// ```rust
/// use activitystreams_new::primitives::{OneOrMany, AnyString};
@ -334,7 +334,7 @@ impl OneOrMany<AnyString> {
/// ```
pub fn add_xsd_string<T>(&mut self, string: T) -> &mut Self
where
T: Into<XsdString>,
T: Into<String>,
{
self.add(string.into())
}
@ -678,7 +678,7 @@ impl Unit {
/// ```
pub fn custom<T>(string: T) -> Self
where
T: Into<XsdString>,
T: Into<String>,
{
Unit(Either::Right(string.into()))
}
@ -697,12 +697,12 @@ impl Unit {
/// Fetch a custom unit
///
/// ```rust
/// use activitystreams_new::primitives::{Unit, XsdString};
/// use activitystreams_new::primitives::Unit;
///
/// assert!(Unit::custom("Yards").as_custom() == Some(&XsdString::from("Yards")));
/// assert!(Unit::custom("Yards").as_custom() == Some("Yards"));
/// ```
pub fn as_custom(&self) -> Option<&XsdString> {
self.0.as_ref().right()
pub fn as_custom(&self) -> Option<&str> {
self.0.as_ref().right().map(|r| r.as_str())
}
}
@ -759,8 +759,8 @@ impl<T> From<Vec<T>> for OneOrMany<T> {
}
}
impl From<XsdString> for AnyString {
fn from(s: XsdString) -> Self {
impl From<String> for AnyString {
fn from(s: String) -> Self {
AnyString::from_xsd_string(s)
}
}
@ -771,8 +771,8 @@ impl From<RdfLangString> for AnyString {
}
}
impl From<XsdString> for OneOrMany<AnyString> {
fn from(s: XsdString) -> Self {
impl From<String> for OneOrMany<AnyString> {
fn from(s: String) -> Self {
OneOrMany::<AnyString>::from_xsd_string(s)
}
}

View file

@ -32,7 +32,7 @@
//! pub struct PublicKeyValues {
//! pub id: XsdAnyUri,
//! pub owner: XsdAnyUri,
//! pub public_key_pem: XsdString,
//! pub public_key_pem: String,
//! }
//!
//! #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
@ -195,7 +195,7 @@
//! }
//!
//! /// Borrow the public key's PEM encoded value
//! fn key_pem<'a>(&'a self) -> &'a XsdString
//! fn key_pem<'a>(&'a self) -> &'a str
//! where
//! Inner: 'a,
//! {
@ -206,7 +206,7 @@
//! ///
//! /// In a real application, this might take a different type, such as RSA's RSAPublicKey, or
//! /// OpenSSL's or Ring's version
//! fn set_key_pem(&mut self, pem: XsdString) -> &mut Self {
//! fn set_key_pem(&mut self, pem: String) -> &mut Self {
//! self.public_key_mut().public_key.public_key_pem = pem;
//! self
//! }
@ -236,12 +236,12 @@
//! extended_person
//! .set_kind(PersonType)
//! .set_id("https://example.com/user".parse()?)
//! .set_name(XsdString::from("Demo User"))
//! .set_preferred_username(XsdString::from("user"))
//! .set_name("Demo User".to_string())
//! .set_preferred_username("user".to_string())
//! .set_outbox("https://example.com/user/outbox".parse()?)
//! .set_key_pem(XsdString::from(
//! "------ BEGIN PUBLIC KEY ------\nasdfasdfasdfasdfasdfasdf..."
//! ))
//! .set_key_pem(
//! "------ BEGIN PUBLIC KEY ------\nasdfasdfasdfasdfasdfasdf...".to_string()
//! )
//! .set_key_owner("https://example.com/user".parse()?)
//! .set_key_id("https://example.com/user#main-key".parse()?);
//!