Update README

This commit is contained in:
asonix 2020-06-03 15:53:54 -05:00
parent 19a9477eb2
commit 99c7e9aa55

View file

@ -88,14 +88,14 @@ With multiple values
It may seem like interacting with these types might get unweildy, there are some custom methods It may seem like interacting with these types might get unweildy, there are some custom methods
implemented on the `OneOrMany` type depending on what's inside of it. implemented on the `OneOrMany` type depending on what's inside of it.
```rust ```rust,ignore
fn from_xsd_string<T>(&mut self, T) -> Self; fn from_xsd_string<T>(&mut self, T) -> Self;
fn from_rdf_lang_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 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 single_rdf_lang_string(self) -> Option<RdfLangString>;
fn add_xsd_string<T>(&mut self, T) -> &mut Self; fn add_xsd_string<T>(&mut self, T) -> &mut Self;
@ -103,10 +103,10 @@ fn add_rdf_lang_string<T>(&mut self, T) -> &mut Self;
``` ```
These methods provide access to setting and fetching uniformly typed data, as well as deleting 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 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. 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 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 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. `Into` or `TryFrom` and `TryInto` for types you might expect them to (e.g.
@ -121,7 +121,7 @@ will be located in the innermost struct. In order to avoid writing code like
automatically implmeneted for provided types. automatically implmeneted for provided types.
For example, the `BaseExt` trait provides the following methods for `context`, For example, the `BaseExt` trait provides the following methods for `context`,
```rust ```rust,ignore
fn context(&self) -> Option<&OneOrMany<AnyBase>>; fn context(&self) -> Option<&OneOrMany<AnyBase>>;
fn set_context<T>(&mut self, context: T) -> &mut Self fn set_context<T>(&mut self, context: T) -> &mut Self
@ -142,7 +142,7 @@ fn delete_context(&mut self) -> &mut Self;
``` ```
For fields with more specific bounds, like `id`, For fields with more specific bounds, like `id`,
```rust ```rust,ignore
fn id(&self) -> Option<&XsdAnyUri>; fn id(&self) -> Option<&XsdAnyUri>;
fn set_id(&mut self, XsdAnyUri) -> &mut Self; fn set_id(&mut self, XsdAnyUri) -> &mut Self;
fn take_id(&self) -> Option<XsdAnyUri>; fn take_id(&self) -> Option<XsdAnyUri>;
@ -164,14 +164,14 @@ If you want to make a function that manipulates an Activity, but not a normal ob
bound the function like so: bound the function like so:
```rust ```rust
use activitystreams_new::{base::BaseExt, context, markers::Activity}; use activitystreams_new::{base::BaseExt, context, markers::Activity, uri};
fn manipulator<T>(mut activity: T) -> Result<(), SomeErrorType> fn manipulator<T, Kind>(mut activity: T) -> Result<(), anyhow::Error>
where where
T: Activity + BaseExt<Kind>, T: Activity + BaseExt<Kind>,
{ {
activity activity
.set_id("https://example.com".parse()?) .set_id(uri!("https://example.com"))
.set_context(context()); .set_context(context());
Ok(()) Ok(())
} }
@ -205,7 +205,7 @@ use activitystreams_new::{
context, context,
object::{ApObject, Video}, object::{ApObject, Video},
prelude::*, prelude::*,
primitives::{XsdAnyUri, XsdString}, uri,
}; };
fn main() -> Result<(), anyhow::Error> { fn main() -> Result<(), anyhow::Error> {
@ -213,12 +213,12 @@ fn main() -> Result<(), anyhow::Error> {
video video
.set_context(context()) .set_context(context())
.set_id("https://example.com/@example/lions".parse()?) .set_id(uri!("https://example.com/@example/lions"))
.set_media_type("video/webm".parse()?) .set_media_type("video/webm".parse()?)
.set_url("https://example.com/@example/lions/video.webm".parse::<XsdAnyUri>()?) .set_url(uri!("https://example.com/@example/lions/video.webm"))
.set_summary(XsdString::from("A cool video")) .set_summary("A cool video")
.set_duration("PT4M20S".parse()?) .set_duration("PT4M20S".parse()?)
.set_shares("https://example.com/@example/lions/video.webm#shares".parse()?); .set_shares(uri!("https://example.com/@example/lions/video.webm#shares"));
println!("Video, {:#?}", video); println!("Video, {:#?}", video);