mirror of
https://git.asonix.dog/asonix/activitystreams.git
synced 2024-11-25 05:11:03 +00:00
Add AnyImage
This commit is contained in:
parent
9593d79bee
commit
8e6950b549
7 changed files with 36 additions and 40 deletions
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "activitystreams"
|
||||
description = "Activity Streams in Rust"
|
||||
version = "0.5.0-alpha.0"
|
||||
version = "0.5.0-alpha.1"
|
||||
license = "GPL-3.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
|
||||
|
|
|
@ -9,7 +9,7 @@ __A set of Traits and Types that make up the ActivityStreams and ActivityPub spe
|
|||
|
||||
First, add ActivityStreams to your dependencies
|
||||
```toml
|
||||
activitystreams = "0.5.0-alpha.0"
|
||||
activitystreams = "0.5.0-alpha.1"
|
||||
```
|
||||
|
||||
### Types
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
//!
|
||||
//! First, add ActivityStreams to your dependencies
|
||||
//! ```toml
|
||||
//! activitystreams = "0.5.0-alpha.0"
|
||||
//! activitystreams = "0.5.0-alpha.1"
|
||||
//! ```
|
||||
//!
|
||||
//! ### Types
|
||||
|
|
|
@ -23,10 +23,6 @@ use crate::{
|
|||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct ApImageBox(pub Box<Image>);
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, PropRefs)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[prop_refs(Object)]
|
||||
|
@ -234,15 +230,3 @@ pub struct Video {
|
|||
#[prop_refs]
|
||||
pub ap_object_props: ApObjectProperties,
|
||||
}
|
||||
|
||||
impl From<Image> for ApImageBox {
|
||||
fn from(i: Image) -> Self {
|
||||
ApImageBox(Box::new(i))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ApImageBox> for Image {
|
||||
fn from(i: ApImageBox) -> Self {
|
||||
*i.0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,3 +38,33 @@ use crate::wrapper_type;
|
|||
/// `Collection` and `OrderedCollection`.
|
||||
#[cfg_attr(feature = "types", wrapper_type)]
|
||||
pub trait Object: std::fmt::Debug {}
|
||||
|
||||
#[cfg(feature = "types")]
|
||||
/// Describes any kind of Image
|
||||
///
|
||||
/// Since Image is "concrete" in the ActivityStreams spec, but multiple fields in ObjectProperties
|
||||
/// require an "Image", this type acts as a filter to ensure only Images can be serialized or
|
||||
/// deserialized, but allows any adjacent fields through
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct AnyImage {
|
||||
kind: self::kind::ImageType,
|
||||
|
||||
#[serde(flatten)]
|
||||
rest: std::collections::HashMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
impl AnyImage {
|
||||
pub fn from_concrete<T>(t: T) -> Result<Self, serde_json::Error>
|
||||
where
|
||||
T: Object + serde::ser::Serialize,
|
||||
{
|
||||
serde_json::from_value(serde_json::to_value(t)?)
|
||||
}
|
||||
|
||||
pub fn to_concrete<T>(self) -> Result<T, serde_json::Error>
|
||||
where
|
||||
T: Object + serde::de::DeserializeOwned,
|
||||
{
|
||||
serde_json::from_value(serde_json::to_value(self)?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
|
||||
use crate::{
|
||||
link::LinkBox,
|
||||
object::{apub::ApImageBox, streams::ImageBox, ObjectBox},
|
||||
object::{AnyImage, ObjectBox},
|
||||
primitives::*,
|
||||
properties,
|
||||
};
|
||||
|
@ -235,8 +235,7 @@ properties! {
|
|||
],
|
||||
types [
|
||||
XsdAnyUri,
|
||||
ImageBox,
|
||||
ApImageBox,
|
||||
AnyImage,
|
||||
LinkBox,
|
||||
],
|
||||
},
|
||||
|
@ -252,8 +251,7 @@ properties! {
|
|||
],
|
||||
types [
|
||||
XsdAnyUri,
|
||||
ImageBox,
|
||||
ApImageBox,
|
||||
AnyImage,
|
||||
LinkBox,
|
||||
],
|
||||
},
|
||||
|
|
|
@ -23,10 +23,6 @@ use crate::{
|
|||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct ImageBox(pub Box<Image>);
|
||||
|
||||
/// Represents any kind of multi-paragraph written work.
|
||||
#[derive(Clone, Debug, Default, Deserialize, PropRefs, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -274,15 +270,3 @@ pub struct Video {
|
|||
#[prop_refs]
|
||||
pub object_props: ObjectProperties,
|
||||
}
|
||||
|
||||
impl From<Image> for ImageBox {
|
||||
fn from(i: Image) -> Self {
|
||||
ImageBox(Box::new(i))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ImageBox> for Image {
|
||||
fn from(i: ImageBox) -> Self {
|
||||
*i.0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue