Allow &str in places

This commit is contained in:
asonix 2020-06-03 13:41:30 -05:00
parent d37714ff57
commit 05a2bdc98d
6 changed files with 54 additions and 36 deletions

View file

@ -518,12 +518,15 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// # let mut person = ApActor::new(context(), Person::new());
/// use activitystreams_new::prelude::*;
///
/// person.set_preferred_username("user123".into());
/// person.set_preferred_username("user123");
/// # Ok(())
/// # }
/// ```
fn set_preferred_username(&mut self, string: String) -> &mut Self {
self.ap_actor_mut().preferred_username = Some(string);
fn set_preferred_username<T>(&mut self, string: T) -> &mut Self
where
T: Into<String>,
{
self.ap_actor_mut().preferred_username = Some(string.into());
self
}
@ -547,7 +550,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```rust
/// # use activitystreams_new::{actor::{ApActor, Person}, context};
/// # let mut person = ApActor::new(context(), Person::new());
/// # person.set_preferred_username("hey".into());
/// # person.set_preferred_username("hey");
/// use activitystreams_new::prelude::*;
///
/// assert!(person.preferred_username().is_some());

View file

@ -15,7 +15,7 @@
//! .set_id("https://example.com".parse()?)
//! .set_context(context())
//! .add_context(security())
//! .set_name("Hello".to_owned());
//! .set_name("Hello");
//!
//! let any_base = video.into_any_base()?;
//!
@ -454,7 +454,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// video.set_name("hi".to_owned());
/// video.set_name("hi");
/// ```
fn set_name<T>(&mut self, name: T) -> &mut Self
where
@ -473,7 +473,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// #
/// video.set_many_names(vec!["hi".to_owned(), "hey".to_owned()]);
/// video.set_many_names(vec!["hi", "hey"]);
/// ```
fn set_many_names<I, T>(&mut self, items: I) -> &mut Self
where
@ -495,8 +495,8 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// # let mut video = Video::new();
/// #
/// video
/// .add_name("hi".to_owned())
/// .add_name("hey".to_owned());
/// .add_name("hi")
/// .add_name("hey");
/// ```
fn add_name<T>(&mut self, name: T) -> &mut Self
where
@ -535,7 +535,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// use activitystreams_new::prelude::*;
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// # video.set_name("hi".to_owned());
/// # video.set_name("hi");
/// #
///
/// assert!(video.name().is_some());
@ -1800,3 +1800,9 @@ impl From<String> for OneOrMany<AnyBase> {
Self::from_xsd_string(xsd_string)
}
}
impl From<&str> for OneOrMany<AnyBase> {
fn from(xsd_string: &str) -> Self {
Self::from_xsd_string(xsd_string.to_owned())
}
}

View file

@ -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("A cool video".to_owned())
//! .set_summary("A cool video")
//! .set_duration("PT4M20S".parse()?)
//! .set_shares("https://example.com/@example/lions/video.webm#shares".parse()?);
//!
@ -315,7 +315,7 @@ pub mod markers {
//! where
//! T: Activity + BaseExt<Kind>,
//! {
//! some_type.set_name("hi".to_owned());
//! some_type.set_name("hi");
//!
//! some_type
//! }
@ -351,8 +351,8 @@ pub mod prelude {
//! );
//! person
//! .set_outbox("http:/localhost:8080/outbox".parse()?)
//! .set_name("Demo Account".to_owned())
//! .set_preferred_username("demo".to_owned())
//! .set_name("Demo Account")
//! .set_preferred_username("demo")
//! .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("A cool video".to_owned())
//! .set_summary("A cool video")
//! .set_preview(preview.into_any_base()?)
//! .set_duration("PT4M20S".parse()?)
//! .set_shares("http://localhost:8080/video.webm#shares".parse()?);

View file

@ -546,7 +546,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
///
/// video.set_content("hi".to_owned());
/// video.set_content("hi");
/// ```
fn set_content<T>(&mut self, content: T) -> &mut Self
where
@ -565,10 +565,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
///
/// video.set_many_contents(vec![
/// "hi".to_owned(),
/// "hello".to_owned(),
/// ]);
/// video.set_many_contents(vec!["hi", "hello"]);
/// ```
fn set_many_contents<I, T>(&mut self, items: I) -> &mut Self
where
@ -590,8 +587,8 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// # let mut video = Video::new();
///
/// video
/// .add_content("hi".to_owned())
/// .add_content("hello".to_owned());
/// .add_content("hi")
/// .add_content("hello");
/// ```
fn add_content<T>(&mut self, content: T) -> &mut Self
where
@ -629,7 +626,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```rust
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// # video.set_content("content".to_owned());
/// # video.set_content("content");
/// #
/// use activitystreams_new::prelude::*;
///
@ -670,7 +667,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
///
/// video.set_summary("hi".to_owned());
/// video.set_summary("hi");
/// ```
fn set_summary<T>(&mut self, summary: T) -> &mut Self
where
@ -689,10 +686,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
///
/// video.set_many_summaries(vec![
/// "hi".to_owned(),
/// "hello".to_owned(),
/// ]);
/// video.set_many_summaries(vec![ "hi", "hello"]);
/// ```
fn set_many_summaries<I, T>(&mut self, items: I) -> &mut Self
where
@ -714,8 +708,8 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// # let mut video = Video::new();
///
/// video
/// .add_summary("hi".to_owned())
/// .add_summary("hello".to_owned());
/// .add_summary("hi")
/// .add_summary("hello");
/// ```
fn add_summary<T>(&mut self, summary: T) -> &mut Self
where
@ -753,7 +747,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```rust
/// # use activitystreams_new::object::Video;
/// # let mut video = Video::new();
/// # video.set_summary("summary".to_owned());
/// # video.set_summary("summary");
/// #
/// use activitystreams_new::prelude::*;
///

View file

@ -759,6 +759,12 @@ impl<T> From<Vec<T>> for OneOrMany<T> {
}
}
impl From<&str> for AnyString {
fn from(s: &str) -> Self {
AnyString::from_xsd_string(s.to_owned())
}
}
impl From<String> for AnyString {
fn from(s: String) -> Self {
AnyString::from_xsd_string(s)
@ -771,6 +777,12 @@ impl From<RdfLangString> for AnyString {
}
}
impl From<&str> for OneOrMany<AnyString> {
fn from(s: &str) -> Self {
OneOrMany::<AnyString>::from_xsd_string(s.to_owned())
}
}
impl From<String> for OneOrMany<AnyString> {
fn from(s: String) -> Self {
OneOrMany::<AnyString>::from_xsd_string(s)

View file

@ -206,8 +206,11 @@
//! ///
//! /// 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: String) -> &mut Self {
//! self.public_key_mut().public_key.public_key_pem = pem;
//! fn set_key_pem<T>(&mut self, pem: T) -> &mut Self
//! where
//! T: Into<String>,
//! {
//! self.public_key_mut().public_key.public_key_pem = pem.into();
//! self
//! }
//! }
@ -236,11 +239,11 @@
//! extended_person
//! .set_kind(PersonType)
//! .set_id("https://example.com/user".parse()?)
//! .set_name("Demo User".to_string())
//! .set_preferred_username("user".to_string())
//! .set_name("Demo User")
//! .set_preferred_username("user")
//! .set_outbox("https://example.com/user/outbox".parse()?)
//! .set_key_pem(
//! "------ BEGIN PUBLIC KEY ------\nasdfasdfasdfasdfasdfasdf...".to_string()
//! "------ BEGIN PUBLIC KEY ------\nasdfasdfasdfasdfasdfasdf..."
//! )
//! .set_key_owner("https://example.com/user".parse()?)
//! .set_key_id("https://example.com/user#main-key".parse()?);