mirror of
https://git.asonix.dog/asonix/activitystreams.git
synced 2024-11-21 19:31:00 +00:00
Clippy nits, AnyBase::extend
This commit is contained in:
parent
feb42ee3ed
commit
757df7792d
9 changed files with 133 additions and 21 deletions
|
@ -1,5 +1,10 @@
|
|||
# Unreleased
|
||||
|
||||
# 0.7.0-alpha.9
|
||||
- Add default impls for many object kinds
|
||||
- Add `extend` method on AnyBase
|
||||
- Clippy nits
|
||||
|
||||
# 0.7.0-alpha.8
|
||||
- Add `from_arbitrary_json` to AnyBase
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "activitystreams"
|
||||
description = "A set of core types and traits for activitystreams data"
|
||||
version = "0.7.0-alpha.8"
|
||||
version = "0.7.0-alpha.9"
|
||||
license = "GPL-3.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
|
||||
|
|
|
@ -3604,3 +3604,18 @@ impl<T> OriginRefExt for T where T: OriginRef {}
|
|||
impl<T> OptTargetRefExt for T where T: OptTargetRef {}
|
||||
impl<T> OptOriginRefExt for T where T: OptOriginRef {}
|
||||
impl<T> QuestionExt for T where T: AsQuestion {}
|
||||
|
||||
impl<Kind> Default for Activity<Kind>
|
||||
where
|
||||
Kind: Default,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Question {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1637,3 +1637,12 @@ where
|
|||
self.inner_mut().ap_actor_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> Default for Actor<Kind>
|
||||
where
|
||||
Kind: Default,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
32
src/base.rs
32
src/base.rs
|
@ -1120,6 +1120,29 @@ impl AnyBase {
|
|||
Ok(base.into())
|
||||
}
|
||||
|
||||
/// Extend this AnyBase into a kind T where T implements Extends<Kind>
|
||||
///
|
||||
/// This method returns Ok(None) when the AnyBase does not contain an extensible object, i.e.
|
||||
/// it's just an IRI
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() -> Result<(), anyhow::Error> {
|
||||
/// # use activitystreams::{object::Video, base::AnyBase};
|
||||
/// # let video = Video::new();
|
||||
/// # let any_base = AnyBase::from_extended(video)?;
|
||||
/// let video: Video = any_base.extend()?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn extend<T, Kind>(self) -> Result<Option<T>, T::Error>
|
||||
where
|
||||
T: ExtendsExt<Kind>,
|
||||
<T as Extends<Kind>>::Error: From<serde_json::Error>,
|
||||
for<'de> Kind: serde::Deserialize<'de>,
|
||||
{
|
||||
T::from_any_base(self)
|
||||
}
|
||||
|
||||
/// Convert any type that is extended from `Base<Kind>` into an AnyBase for storing
|
||||
///
|
||||
/// ```rust
|
||||
|
@ -1934,3 +1957,12 @@ impl From<&str> for OneOrMany<AnyBase> {
|
|||
Self::from_xsd_string(xsd_string.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> Default for Base<Kind>
|
||||
where
|
||||
Kind: Default,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1563,3 +1563,27 @@ where
|
|||
impl<T, Kind> CollectionExt<Kind> for T where T: AsCollection<Kind> {}
|
||||
impl<T, Kind> CollectionPageExt<Kind> for T where T: AsCollectionPage<Kind> {}
|
||||
impl<T> OrderedCollectionPageExt for T where T: AsOrderedCollectionPage {}
|
||||
|
||||
impl<Kind> Default for Collection<Kind>
|
||||
where
|
||||
Kind: Default,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> Default for CollectionPage<Kind>
|
||||
where
|
||||
Kind: Default,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for OrderedCollectionPage {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -688,3 +688,12 @@ impl<Kind> AsLink<Kind> for Link<Kind> {
|
|||
}
|
||||
|
||||
impl<T, Kind> LinkExt<Kind> for T where T: AsLink<Kind> {}
|
||||
|
||||
impl<Kind> Default for Link<Kind>
|
||||
where
|
||||
Kind: Default,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5609,3 +5609,36 @@ impl AsTombstone for Tombstone {
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> Default for Object<Kind>
|
||||
where
|
||||
Kind: Default,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Place {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Profile {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Relationship {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Tombstone {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,38 +249,23 @@ struct LengthError;
|
|||
|
||||
impl Length {
|
||||
fn is_centimeters(&self) -> bool {
|
||||
match self {
|
||||
Length::Centimeters => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Length::Centimeters)
|
||||
}
|
||||
|
||||
fn is_feet(&self) -> bool {
|
||||
match self {
|
||||
Length::Feet => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Length::Feet)
|
||||
}
|
||||
|
||||
fn is_inches(&self) -> bool {
|
||||
match self {
|
||||
Length::Inches => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Length::Inches)
|
||||
}
|
||||
|
||||
fn is_kilometers(&self) -> bool {
|
||||
match self {
|
||||
Length::Kilometers => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Length::Kilometers)
|
||||
}
|
||||
|
||||
fn is_meters(&self) -> bool {
|
||||
match self {
|
||||
Length::Meters => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, Length::Meters)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue