Add more impls for primitives

This commit is contained in:
asonix 2020-03-14 17:26:22 -05:00
parent 416ac16af2
commit d690f40cf0
12 changed files with 52 additions and 14 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "activitystreams" name = "activitystreams"
description = "Activity Streams in Rust" description = "Activity Streams in Rust"
version = "0.5.0-alpha.4" version = "0.5.0-alpha.5"
license = "GPL-3.0" license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/Aardwolf/activitystreams" repository = "https://git.asonix.dog/Aardwolf/activitystreams"

View file

@ -9,7 +9,7 @@ __A set of Traits and Types that make up the ActivityStreams and ActivityPub spe
First, add ActivityStreams to your dependencies First, add ActivityStreams to your dependencies
```toml ```toml
activitystreams = "0.5.0-alpha.4" activitystreams = "0.5.0-alpha.5"
``` ```
### Types ### Types
@ -177,7 +177,7 @@ There are a number of features that can be disabled in this crate. By default, e
enabled. enabled.
```toml ```toml
activitystreams = { version = "0.5.0-alpha.4", default-features = "false", features = ["derive"] } activitystreams = { version = "0.5.0-alpha.5", default-features = "false", features = ["derive"] }
``` ```
| feature | what you get | | feature | what you get |

View file

@ -25,7 +25,7 @@
//! //!
//! First, add ActivityStreams to your dependencies //! First, add ActivityStreams to your dependencies
//! ```toml //! ```toml
//! activitystreams = "0.5.0-alpha.4" //! activitystreams = "0.5.0-alpha.5"
//! ``` //! ```
//! //!
//! ### Types //! ### Types
@ -193,7 +193,7 @@
//! enabled. //! enabled.
//! //!
//! ```toml //! ```toml
//! activitystreams = { version = "0.5.0-alpha.4", default-features = "false", features = ["derive"] } //! activitystreams = { version = "0.5.0-alpha.5", default-features = "false", features = ["derive"] }
//! ``` //! ```
//! //!
//! | feature | what you get | //! | feature | what you get |

View file

@ -24,7 +24,7 @@
/// ///
/// See [`RFC 2045`](https://tools.ietf.org/html/rfc2045) and /// See [`RFC 2045`](https://tools.ietf.org/html/rfc2045) and
/// [`RFC 2046`](https://tools.ietf.org/html/rfc2046) for more information. /// [`RFC 2046`](https://tools.ietf.org/html/rfc2046) for more information.
#[derive(Clone, Debug)] #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct MimeMediaType(mime::Mime); pub struct MimeMediaType(mime::Mime);
#[derive(Clone, Debug, thiserror::Error)] #[derive(Clone, Debug, thiserror::Error)]
@ -32,6 +32,12 @@ pub struct MimeMediaType(mime::Mime);
/// The error type produced when a MimeMediaType cannot be parsed /// The error type produced when a MimeMediaType cannot be parsed
pub struct MimeMediaTypeError; pub struct MimeMediaTypeError;
impl<'a> PartialEq<&'a str> for MimeMediaType {
fn eq(&self, rhs: &&'a str) -> bool {
self.0.eq(rhs)
}
}
impl From<mime::Mime> for MimeMediaType { impl From<mime::Mime> for MimeMediaType {
fn from(m: mime::Mime) -> Self { fn from(m: mime::Mime) -> Self {
MimeMediaType(m) MimeMediaType(m)

View file

@ -20,7 +20,9 @@
use crate::primitives::XsdString; use crate::primitives::XsdString;
/// The rdf.langString type extends xs.string, and represents a language tagged string in RDF. /// The rdf.langString type extends xs.string, and represents a language tagged string in RDF.
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[derive(
Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
)]
pub struct RdfLangString { pub struct RdfLangString {
/// The content of the langstring /// The content of the langstring
/// ///

View file

@ -50,7 +50,7 @@
/// Note that when relative URI references such as "../prod" are used as values of xsd:anyURI, no /// Note that when relative URI references such as "../prod" are used as values of xsd:anyURI, no
/// attempt is made to determine or keep track of the base URI to which they may be applied. For /// attempt is made to determine or keep track of the base URI to which they may be applied. For
/// more information on URIs, see RFC 2396, Uniform Resource Identifiers (URI): Generic Syntax. /// more information on URIs, see RFC 2396, Uniform Resource Identifiers (URI): Generic Syntax.
#[derive(Clone, Debug)] #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct XsdAnyUri(url::Url); pub struct XsdAnyUri(url::Url);
/// The error type produced when an XsdAnyUri cannot be parsed /// The error type produced when an XsdAnyUri cannot be parsed
@ -76,6 +76,12 @@ impl Default for XsdAnyUri {
} }
} }
impl AsRef<str> for XsdAnyUri {
fn as_ref(&self) -> &str {
self.0.as_ref()
}
}
impl std::convert::TryFrom<String> for XsdAnyUri { impl std::convert::TryFrom<String> for XsdAnyUri {
type Error = XsdAnyUriError; type Error = XsdAnyUriError;

View file

@ -30,7 +30,7 @@
/// range from -14:00 to 14:00. For example, US Eastern Standard Time, which is five hours behind /// range from -14:00 to 14:00. For example, US Eastern Standard Time, which is five hours behind
/// UTC, is represented as -05:00. If no time zone value is present, it is considered unknown; it /// UTC, is represented as -05:00. If no time zone value is present, it is considered unknown; it
/// is not assumed to be UTC. /// is not assumed to be UTC.
#[derive(Clone, Debug)] #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct XsdDateTime(chrono::DateTime<chrono::FixedOffset>); pub struct XsdDateTime(chrono::DateTime<chrono::FixedOffset>);
/// The error type produced when an XsdDateTime cannot be parsed /// The error type produced when an XsdDateTime cannot be parsed

View file

@ -41,7 +41,7 @@
/// This implementation converts Months to Days by multiplying by 31, and converts Years to days by /// This implementation converts Months to Days by multiplying by 31, and converts Years to days by
/// multiplying by 365. If this is an issue for your application, look into specifying days /// multiplying by 365. If this is an issue for your application, look into specifying days
/// directly. /// directly.
#[derive(Clone, Debug)] #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct XsdDuration(chrono::Duration); pub struct XsdDuration(chrono::Duration);
/// The error type produced when an XsdDuration cannot be parsed /// The error type produced when an XsdDuration cannot be parsed

View file

@ -30,7 +30,9 @@
/// (Not a Number). INF is considered to be greater than all other values, while -INF is less than /// (Not a Number). INF is considered to be greater than all other values, while -INF is less than
/// all other values. The value NaN cannot be compared to any other values, although it equals /// all other values. The value NaN cannot be compared to any other values, although it equals
/// itself. /// itself.
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[derive(
Clone, Debug, Default, PartialEq, PartialOrd, Default, serde::Deserialize, serde::Serialize,
)]
#[serde(transparent)] #[serde(transparent)]
pub struct XsdFloat(f64); pub struct XsdFloat(f64);

View file

@ -32,7 +32,7 @@
/// itself. /// itself.
/// ///
/// This type also validates that a float is at least 0.0 /// This type also validates that a float is at least 0.0
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, PartialEq, PartialOrd, Default, serde::Deserialize, serde::Serialize)]
#[serde(transparent)] #[serde(transparent)]
pub struct XsdNonNegativeFloat(f64); pub struct XsdNonNegativeFloat(f64);

View file

@ -21,7 +21,18 @@
/// ///
/// An xsd:nonNegativeInteger is a sequence of digits, optionally preceded by a + sign. Leading /// An xsd:nonNegativeInteger is a sequence of digits, optionally preceded by a + sign. Leading
/// zeros are permitted, but decimal points are not. /// zeros are permitted, but decimal points are not.
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[derive(
Clone,
Debug,
Default,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
serde::Deserialize,
serde::Serialize,
)]
#[serde(transparent)] #[serde(transparent)]
pub struct XsdNonNegativeInteger(u64); pub struct XsdNonNegativeInteger(u64);

View file

@ -29,7 +29,18 @@
/// The xsd:string type has a whiteSpace facet of preserve, which means that all whitespace /// The xsd:string type has a whiteSpace facet of preserve, which means that all whitespace
/// characters (spaces, tabs, carriage returns, and line feeds) are preserved by the processor. /// characters (spaces, tabs, carriage returns, and line feeds) are preserved by the processor.
/// This is in contrast to two types derived from it: normalizedString, and token. /// This is in contrast to two types derived from it: normalizedString, and token.
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[derive(
Clone,
Debug,
Default,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
serde::Deserialize,
serde::Serialize,
)]
#[serde(transparent)] #[serde(transparent)]
pub struct XsdString(String); pub struct XsdString(String);