Basic Ext implementation for new activitystreams
This commit is contained in:
commit
6a3005ca6c
10 changed files with 1321 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/target
|
||||
/artifacts
|
||||
Cargo.lock
|
18
Cargo.toml
Normal file
18
Cargo.toml
Normal file
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "activitystreams-ext"
|
||||
version = "0.1.0"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
activitystreams-new = { version = "0.1.0", git = "https://git.asonix.dog/asonix/activitystreams-sketch" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = "1.0"
|
||||
|
||||
[patch.crates-io]
|
||||
typed-builder = { git = "https://git.asonix.dog/asonix/typed-builder" }
|
6
Dockerfile.arm64v8
Normal file
6
Dockerfile.arm64v8
Normal file
|
@ -0,0 +1,6 @@
|
|||
FROM arm64v8/nginx:mainline-alpine
|
||||
|
||||
COPY html/ /usr/share/nginx/html/
|
||||
|
||||
RUN chown -R nginx:nginx /usr/share/nginx/html
|
||||
|
54
build.sh
Executable file
54
build.sh
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
BUILD_DATE=$(date)
|
||||
VERSION=$1
|
||||
MIGRATIONS=$2
|
||||
|
||||
function require() {
|
||||
if [ "$1" = "" ]; then
|
||||
echo "input '$2' required"
|
||||
print_help
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function print_help() {
|
||||
echo "build.sh"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " build.sh [version]"
|
||||
echo ""
|
||||
echo "Args:"
|
||||
echo " version: The version of the current container"
|
||||
}
|
||||
|
||||
require "$VERSION" "version"
|
||||
|
||||
if ! docker run --rm -it arm64v8/ubuntu:19.10 /bin/bash -c 'echo "docker is configured correctly"'; then
|
||||
echo "docker is not configured to run on qemu-emulated architectures, fixing will require sudo"
|
||||
sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
||||
fi
|
||||
|
||||
set -xe
|
||||
|
||||
cargo clean
|
||||
cargo doc --no-deps
|
||||
|
||||
mkdir -p artifacts
|
||||
rm -rf artifacts/html
|
||||
cp -r ./target/doc artifacts/html
|
||||
|
||||
docker build \
|
||||
--pull \
|
||||
--no-cache \
|
||||
--build-arg BUILD_DATE="${BUILD_DATE}" \
|
||||
--build-arg TAG="${TAG}" \
|
||||
-f Dockerfile.arm64v8 \
|
||||
-t "asonix/activitystreams-ext-docs:${VERSION}-arm64v8" \
|
||||
-t "asonix/activitystreams-ext-docs:latest-arm64v8" \
|
||||
-t "asonix/activitystreams-ext-docs:latest" \
|
||||
./artifacts
|
||||
|
||||
docker push "asonix/activitystreams-ext-docs:${VERSION}-arm64v8"
|
||||
docker push "asonix/activitystreams-ext-docs:latest-arm64v8"
|
||||
docker push "asonix/activitystreams-ext-docs:latest"
|
71
examples/public_key.rs
Normal file
71
examples/public_key.rs
Normal file
|
@ -0,0 +1,71 @@
|
|||
use activitystreams_ext::{Ext1, UnparsedExtension};
|
||||
use activitystreams_new::{
|
||||
actor::{ApActor, Person},
|
||||
context,
|
||||
prelude::*,
|
||||
primitives::XsdAnyUri,
|
||||
security,
|
||||
unparsed::UnparsedMutExt,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PublicKey {
|
||||
public_key: PublicKeyInner,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PublicKeyInner {
|
||||
id: XsdAnyUri,
|
||||
owner: XsdAnyUri,
|
||||
public_key_pem: String,
|
||||
}
|
||||
|
||||
impl<U> UnparsedExtension<U> for PublicKey
|
||||
where
|
||||
U: UnparsedMutExt,
|
||||
{
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
||||
Ok(PublicKey {
|
||||
public_key: unparsed_mut.remove("publicKey")?,
|
||||
})
|
||||
}
|
||||
|
||||
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
|
||||
unparsed_mut.insert("publicKey", self.public_key)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub type ExtendedPerson = Ext1<ApActor<Person>, PublicKey>;
|
||||
|
||||
fn main() -> Result<(), anyhow::Error> {
|
||||
let actor = ApActor::new(
|
||||
"http://in.box".parse()?,
|
||||
"http://out.box".parse()?,
|
||||
Person::new(),
|
||||
);
|
||||
|
||||
let mut person = Ext1::new(
|
||||
actor,
|
||||
PublicKey {
|
||||
public_key: PublicKeyInner {
|
||||
id: "http://key.id".parse()?,
|
||||
owner: "http://owner.id".parse()?,
|
||||
public_key_pem: "asdfasdfasdf".to_owned(),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
person.set_context(context()).add_context(security());
|
||||
|
||||
let any_base = person.into_any_base()?;
|
||||
println!("any_base: {:#?}", any_base);
|
||||
let person = ExtendedPerson::from_any_base(any_base)?;
|
||||
|
||||
println!("person: {:#?}", person);
|
||||
Ok(())
|
||||
}
|
201
src/ext1.rs
Normal file
201
src/ext1.rs
Normal file
|
@ -0,0 +1,201 @@
|
|||
use crate::Ext1;
|
||||
use activitystreams_new::{
|
||||
activity::{
|
||||
Activity, ActorAndObjectRef, AsActivity, AsQuestion, OptOriginRef, OptTargetRef, OriginRef,
|
||||
Question, TargetRef,
|
||||
},
|
||||
actor::{ApActor, AsApActor},
|
||||
base::{AnyBase, AsBase, Base},
|
||||
collection::{AsCollection, AsCollectionPage, Collection, CollectionPage},
|
||||
markers,
|
||||
object::{ApObject, AsApObject, AsObject, Object},
|
||||
primitives::OneOrMany,
|
||||
};
|
||||
|
||||
impl<Inner, A> markers::Base for Ext1<Inner, A> where Inner: markers::Base {}
|
||||
impl<Inner, A> markers::Object for Ext1<Inner, A> where Inner: markers::Object {}
|
||||
impl<Inner, A> markers::Collection for Ext1<Inner, A> where Inner: markers::Collection {}
|
||||
impl<Inner, A> markers::CollectionPage for Ext1<Inner, A> where Inner: markers::CollectionPage {}
|
||||
impl<Inner, A> markers::Actor for Ext1<Inner, A> where Inner: markers::Actor {}
|
||||
impl<Inner, A> markers::Activity for Ext1<Inner, A> where Inner: markers::Activity {}
|
||||
impl<Inner, A> markers::IntransitiveActivity for Ext1<Inner, A> where
|
||||
Inner: markers::IntransitiveActivity
|
||||
{
|
||||
}
|
||||
|
||||
impl<Inner, A, Kind> AsBase<Kind> for Ext1<Inner, A>
|
||||
where
|
||||
Inner: AsBase<Kind>,
|
||||
{
|
||||
fn base_ref(&self) -> &Base<Kind> {
|
||||
self.inner.base_ref()
|
||||
}
|
||||
|
||||
fn base_mut(&mut self) -> &mut Base<Kind> {
|
||||
self.inner.base_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, Kind> AsObject<Kind> for Ext1<Inner, A>
|
||||
where
|
||||
Inner: AsObject<Kind>,
|
||||
{
|
||||
fn object_ref(&self) -> &Object<Kind> {
|
||||
self.inner.object_ref()
|
||||
}
|
||||
|
||||
fn object_mut(&mut self) -> &mut Object<Kind> {
|
||||
self.inner.object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, ApInner> AsApObject<ApInner> for Ext1<Inner, A>
|
||||
where
|
||||
Inner: AsApObject<ApInner>,
|
||||
{
|
||||
fn ap_object_ref(&self) -> &ApObject<ApInner> {
|
||||
self.inner.ap_object_ref()
|
||||
}
|
||||
|
||||
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
|
||||
self.inner.ap_object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, Kind> AsCollection<Kind> for Ext1<Inner, A>
|
||||
where
|
||||
Inner: AsCollection<Kind>,
|
||||
{
|
||||
fn collection_ref(&self) -> &Collection<Kind> {
|
||||
self.inner.collection_ref()
|
||||
}
|
||||
|
||||
fn collection_mut(&mut self) -> &mut Collection<Kind> {
|
||||
self.inner.collection_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, Kind> AsCollectionPage<Kind> for Ext1<Inner, A>
|
||||
where
|
||||
Inner: AsCollectionPage<Kind>,
|
||||
{
|
||||
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
|
||||
self.inner.collection_page_ref()
|
||||
}
|
||||
|
||||
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
|
||||
self.inner.collection_page_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, ApInner> AsApActor<ApInner> for Ext1<Inner, A>
|
||||
where
|
||||
Inner: AsApActor<ApInner>,
|
||||
{
|
||||
fn ap_actor_ref(&self) -> &ApActor<ApInner> {
|
||||
self.inner.ap_actor_ref()
|
||||
}
|
||||
|
||||
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
|
||||
self.inner.ap_actor_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, Kind> AsActivity<Kind> for Ext1<Inner, A>
|
||||
where
|
||||
Inner: AsActivity<Kind>,
|
||||
{
|
||||
fn activity_ref(&self) -> &Activity<Kind> {
|
||||
self.inner.activity_ref()
|
||||
}
|
||||
|
||||
fn activity_mut(&mut self) -> &mut Activity<Kind> {
|
||||
self.inner.activity_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A> ActorAndObjectRef for Ext1<Inner, A>
|
||||
where
|
||||
Inner: ActorAndObjectRef,
|
||||
{
|
||||
fn actor_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.actor_field_ref()
|
||||
}
|
||||
|
||||
fn actor_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.actor_field_mut()
|
||||
}
|
||||
|
||||
fn object_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.object_field_ref()
|
||||
}
|
||||
|
||||
fn object_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.object_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A> TargetRef for Ext1<Inner, A>
|
||||
where
|
||||
Inner: TargetRef,
|
||||
{
|
||||
fn target_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.target_field_ref()
|
||||
}
|
||||
|
||||
fn target_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.target_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A> OriginRef for Ext1<Inner, A>
|
||||
where
|
||||
Inner: OriginRef,
|
||||
{
|
||||
fn origin_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.origin_field_ref()
|
||||
}
|
||||
|
||||
fn origin_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.origin_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A> OptTargetRef for Ext1<Inner, A>
|
||||
where
|
||||
Inner: OptTargetRef,
|
||||
{
|
||||
fn target_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
|
||||
self.inner.target_field_ref()
|
||||
}
|
||||
|
||||
fn target_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
|
||||
self.inner.target_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A> OptOriginRef for Ext1<Inner, A>
|
||||
where
|
||||
Inner: OptOriginRef,
|
||||
{
|
||||
fn origin_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
|
||||
self.inner.origin_field_ref()
|
||||
}
|
||||
|
||||
fn origin_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
|
||||
self.inner.origin_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A> AsQuestion for Ext1<Inner, A>
|
||||
where
|
||||
Inner: AsQuestion,
|
||||
{
|
||||
fn question_ref(&self) -> &Question {
|
||||
self.inner.question_ref()
|
||||
}
|
||||
|
||||
fn question_mut(&mut self) -> &mut Question {
|
||||
self.inner.question_mut()
|
||||
}
|
||||
}
|
201
src/ext2.rs
Normal file
201
src/ext2.rs
Normal file
|
@ -0,0 +1,201 @@
|
|||
use crate::Ext2;
|
||||
use activitystreams_new::{
|
||||
activity::{
|
||||
Activity, ActorAndObjectRef, AsActivity, AsQuestion, OptOriginRef, OptTargetRef, OriginRef,
|
||||
Question, TargetRef,
|
||||
},
|
||||
actor::{ApActor, AsApActor},
|
||||
base::{AnyBase, AsBase, Base},
|
||||
collection::{AsCollection, AsCollectionPage, Collection, CollectionPage},
|
||||
markers,
|
||||
object::{ApObject, AsApObject, AsObject, Object},
|
||||
primitives::OneOrMany,
|
||||
};
|
||||
|
||||
impl<Inner, A, B> markers::Base for Ext2<Inner, A, B> where Inner: markers::Base {}
|
||||
impl<Inner, A, B> markers::Object for Ext2<Inner, A, B> where Inner: markers::Object {}
|
||||
impl<Inner, A, B> markers::Collection for Ext2<Inner, A, B> where Inner: markers::Collection {}
|
||||
impl<Inner, A, B> markers::CollectionPage for Ext2<Inner, A, B> where Inner: markers::CollectionPage {}
|
||||
impl<Inner, A, B> markers::Actor for Ext2<Inner, A, B> where Inner: markers::Actor {}
|
||||
impl<Inner, A, B> markers::Activity for Ext2<Inner, A, B> where Inner: markers::Activity {}
|
||||
impl<Inner, A, B> markers::IntransitiveActivity for Ext2<Inner, A, B> where
|
||||
Inner: markers::IntransitiveActivity
|
||||
{
|
||||
}
|
||||
|
||||
impl<Inner, A, B, Kind> AsBase<Kind> for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: AsBase<Kind>,
|
||||
{
|
||||
fn base_ref(&self) -> &Base<Kind> {
|
||||
self.inner.base_ref()
|
||||
}
|
||||
|
||||
fn base_mut(&mut self) -> &mut Base<Kind> {
|
||||
self.inner.base_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, Kind> AsObject<Kind> for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: AsObject<Kind>,
|
||||
{
|
||||
fn object_ref(&self) -> &Object<Kind> {
|
||||
self.inner.object_ref()
|
||||
}
|
||||
|
||||
fn object_mut(&mut self) -> &mut Object<Kind> {
|
||||
self.inner.object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, ApInner> AsApObject<ApInner> for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: AsApObject<ApInner>,
|
||||
{
|
||||
fn ap_object_ref(&self) -> &ApObject<ApInner> {
|
||||
self.inner.ap_object_ref()
|
||||
}
|
||||
|
||||
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
|
||||
self.inner.ap_object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, Kind> AsCollection<Kind> for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: AsCollection<Kind>,
|
||||
{
|
||||
fn collection_ref(&self) -> &Collection<Kind> {
|
||||
self.inner.collection_ref()
|
||||
}
|
||||
|
||||
fn collection_mut(&mut self) -> &mut Collection<Kind> {
|
||||
self.inner.collection_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, Kind> AsCollectionPage<Kind> for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: AsCollectionPage<Kind>,
|
||||
{
|
||||
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
|
||||
self.inner.collection_page_ref()
|
||||
}
|
||||
|
||||
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
|
||||
self.inner.collection_page_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, ApInner> AsApActor<ApInner> for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: AsApActor<ApInner>,
|
||||
{
|
||||
fn ap_actor_ref(&self) -> &ApActor<ApInner> {
|
||||
self.inner.ap_actor_ref()
|
||||
}
|
||||
|
||||
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
|
||||
self.inner.ap_actor_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, Kind> AsActivity<Kind> for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: AsActivity<Kind>,
|
||||
{
|
||||
fn activity_ref(&self) -> &Activity<Kind> {
|
||||
self.inner.activity_ref()
|
||||
}
|
||||
|
||||
fn activity_mut(&mut self) -> &mut Activity<Kind> {
|
||||
self.inner.activity_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B> ActorAndObjectRef for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: ActorAndObjectRef,
|
||||
{
|
||||
fn actor_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.actor_field_ref()
|
||||
}
|
||||
|
||||
fn actor_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.actor_field_mut()
|
||||
}
|
||||
|
||||
fn object_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.object_field_ref()
|
||||
}
|
||||
|
||||
fn object_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.object_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B> TargetRef for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: TargetRef,
|
||||
{
|
||||
fn target_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.target_field_ref()
|
||||
}
|
||||
|
||||
fn target_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.target_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B> OriginRef for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: OriginRef,
|
||||
{
|
||||
fn origin_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.origin_field_ref()
|
||||
}
|
||||
|
||||
fn origin_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.origin_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B> OptTargetRef for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: OptTargetRef,
|
||||
{
|
||||
fn target_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
|
||||
self.inner.target_field_ref()
|
||||
}
|
||||
|
||||
fn target_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
|
||||
self.inner.target_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B> OptOriginRef for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: OptOriginRef,
|
||||
{
|
||||
fn origin_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
|
||||
self.inner.origin_field_ref()
|
||||
}
|
||||
|
||||
fn origin_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
|
||||
self.inner.origin_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B> AsQuestion for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: AsQuestion,
|
||||
{
|
||||
fn question_ref(&self) -> &Question {
|
||||
self.inner.question_ref()
|
||||
}
|
||||
|
||||
fn question_mut(&mut self) -> &mut Question {
|
||||
self.inner.question_mut()
|
||||
}
|
||||
}
|
204
src/ext3.rs
Normal file
204
src/ext3.rs
Normal file
|
@ -0,0 +1,204 @@
|
|||
use crate::Ext3;
|
||||
use activitystreams_new::{
|
||||
activity::{
|
||||
Activity, ActorAndObjectRef, AsActivity, AsQuestion, OptOriginRef, OptTargetRef, OriginRef,
|
||||
Question, TargetRef,
|
||||
},
|
||||
actor::{ApActor, AsApActor},
|
||||
base::{AnyBase, AsBase, Base},
|
||||
collection::{AsCollection, AsCollectionPage, Collection, CollectionPage},
|
||||
markers,
|
||||
object::{ApObject, AsApObject, AsObject, Object},
|
||||
primitives::OneOrMany,
|
||||
};
|
||||
|
||||
impl<Inner, A, B, C> markers::Base for Ext3<Inner, A, B, C> where Inner: markers::Base {}
|
||||
impl<Inner, A, B, C> markers::Object for Ext3<Inner, A, B, C> where Inner: markers::Object {}
|
||||
impl<Inner, A, B, C> markers::Collection for Ext3<Inner, A, B, C> where Inner: markers::Collection {}
|
||||
impl<Inner, A, B, C> markers::CollectionPage for Ext3<Inner, A, B, C> where
|
||||
Inner: markers::CollectionPage
|
||||
{
|
||||
}
|
||||
impl<Inner, A, B, C> markers::Actor for Ext3<Inner, A, B, C> where Inner: markers::Actor {}
|
||||
impl<Inner, A, B, C> markers::Activity for Ext3<Inner, A, B, C> where Inner: markers::Activity {}
|
||||
impl<Inner, A, B, C> markers::IntransitiveActivity for Ext3<Inner, A, B, C> where
|
||||
Inner: markers::IntransitiveActivity
|
||||
{
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, Kind> AsBase<Kind> for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: AsBase<Kind>,
|
||||
{
|
||||
fn base_ref(&self) -> &Base<Kind> {
|
||||
self.inner.base_ref()
|
||||
}
|
||||
|
||||
fn base_mut(&mut self) -> &mut Base<Kind> {
|
||||
self.inner.base_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, Kind> AsObject<Kind> for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: AsObject<Kind>,
|
||||
{
|
||||
fn object_ref(&self) -> &Object<Kind> {
|
||||
self.inner.object_ref()
|
||||
}
|
||||
|
||||
fn object_mut(&mut self) -> &mut Object<Kind> {
|
||||
self.inner.object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, ApInner> AsApObject<ApInner> for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: AsApObject<ApInner>,
|
||||
{
|
||||
fn ap_object_ref(&self) -> &ApObject<ApInner> {
|
||||
self.inner.ap_object_ref()
|
||||
}
|
||||
|
||||
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
|
||||
self.inner.ap_object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, Kind> AsCollection<Kind> for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: AsCollection<Kind>,
|
||||
{
|
||||
fn collection_ref(&self) -> &Collection<Kind> {
|
||||
self.inner.collection_ref()
|
||||
}
|
||||
|
||||
fn collection_mut(&mut self) -> &mut Collection<Kind> {
|
||||
self.inner.collection_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, Kind> AsCollectionPage<Kind> for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: AsCollectionPage<Kind>,
|
||||
{
|
||||
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
|
||||
self.inner.collection_page_ref()
|
||||
}
|
||||
|
||||
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
|
||||
self.inner.collection_page_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, ApInner> AsApActor<ApInner> for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: AsApActor<ApInner>,
|
||||
{
|
||||
fn ap_actor_ref(&self) -> &ApActor<ApInner> {
|
||||
self.inner.ap_actor_ref()
|
||||
}
|
||||
|
||||
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
|
||||
self.inner.ap_actor_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, Kind> AsActivity<Kind> for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: AsActivity<Kind>,
|
||||
{
|
||||
fn activity_ref(&self) -> &Activity<Kind> {
|
||||
self.inner.activity_ref()
|
||||
}
|
||||
|
||||
fn activity_mut(&mut self) -> &mut Activity<Kind> {
|
||||
self.inner.activity_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C> ActorAndObjectRef for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: ActorAndObjectRef,
|
||||
{
|
||||
fn actor_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.actor_field_ref()
|
||||
}
|
||||
|
||||
fn actor_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.actor_field_mut()
|
||||
}
|
||||
|
||||
fn object_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.object_field_ref()
|
||||
}
|
||||
|
||||
fn object_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.object_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C> TargetRef for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: TargetRef,
|
||||
{
|
||||
fn target_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.target_field_ref()
|
||||
}
|
||||
|
||||
fn target_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.target_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C> OriginRef for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: OriginRef,
|
||||
{
|
||||
fn origin_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.origin_field_ref()
|
||||
}
|
||||
|
||||
fn origin_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.origin_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C> OptTargetRef for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: OptTargetRef,
|
||||
{
|
||||
fn target_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
|
||||
self.inner.target_field_ref()
|
||||
}
|
||||
|
||||
fn target_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
|
||||
self.inner.target_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C> OptOriginRef for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: OptOriginRef,
|
||||
{
|
||||
fn origin_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
|
||||
self.inner.origin_field_ref()
|
||||
}
|
||||
|
||||
fn origin_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
|
||||
self.inner.origin_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C> AsQuestion for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: AsQuestion,
|
||||
{
|
||||
fn question_ref(&self) -> &Question {
|
||||
self.inner.question_ref()
|
||||
}
|
||||
|
||||
fn question_mut(&mut self) -> &mut Question {
|
||||
self.inner.question_mut()
|
||||
}
|
||||
}
|
207
src/ext4.rs
Normal file
207
src/ext4.rs
Normal file
|
@ -0,0 +1,207 @@
|
|||
use crate::Ext4;
|
||||
use activitystreams_new::{
|
||||
activity::{
|
||||
Activity, ActorAndObjectRef, AsActivity, AsQuestion, OptOriginRef, OptTargetRef, OriginRef,
|
||||
Question, TargetRef,
|
||||
},
|
||||
actor::{ApActor, AsApActor},
|
||||
base::{AnyBase, AsBase, Base},
|
||||
collection::{AsCollection, AsCollectionPage, Collection, CollectionPage},
|
||||
markers,
|
||||
object::{ApObject, AsApObject, AsObject, Object},
|
||||
primitives::OneOrMany,
|
||||
};
|
||||
|
||||
impl<Inner, A, B, C, D> markers::Base for Ext4<Inner, A, B, C, D> where Inner: markers::Base {}
|
||||
impl<Inner, A, B, C, D> markers::Object for Ext4<Inner, A, B, C, D> where Inner: markers::Object {}
|
||||
impl<Inner, A, B, C, D> markers::Collection for Ext4<Inner, A, B, C, D> where
|
||||
Inner: markers::Collection
|
||||
{
|
||||
}
|
||||
impl<Inner, A, B, C, D> markers::CollectionPage for Ext4<Inner, A, B, C, D> where
|
||||
Inner: markers::CollectionPage
|
||||
{
|
||||
}
|
||||
impl<Inner, A, B, C, D> markers::Actor for Ext4<Inner, A, B, C, D> where Inner: markers::Actor {}
|
||||
impl<Inner, A, B, C, D> markers::Activity for Ext4<Inner, A, B, C, D> where Inner: markers::Activity {}
|
||||
impl<Inner, A, B, C, D> markers::IntransitiveActivity for Ext4<Inner, A, B, C, D> where
|
||||
Inner: markers::IntransitiveActivity
|
||||
{
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D, Kind> AsBase<Kind> for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: AsBase<Kind>,
|
||||
{
|
||||
fn base_ref(&self) -> &Base<Kind> {
|
||||
self.inner.base_ref()
|
||||
}
|
||||
|
||||
fn base_mut(&mut self) -> &mut Base<Kind> {
|
||||
self.inner.base_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D, Kind> AsObject<Kind> for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: AsObject<Kind>,
|
||||
{
|
||||
fn object_ref(&self) -> &Object<Kind> {
|
||||
self.inner.object_ref()
|
||||
}
|
||||
|
||||
fn object_mut(&mut self) -> &mut Object<Kind> {
|
||||
self.inner.object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D, ApInner> AsApObject<ApInner> for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: AsApObject<ApInner>,
|
||||
{
|
||||
fn ap_object_ref(&self) -> &ApObject<ApInner> {
|
||||
self.inner.ap_object_ref()
|
||||
}
|
||||
|
||||
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
|
||||
self.inner.ap_object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D, Kind> AsCollection<Kind> for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: AsCollection<Kind>,
|
||||
{
|
||||
fn collection_ref(&self) -> &Collection<Kind> {
|
||||
self.inner.collection_ref()
|
||||
}
|
||||
|
||||
fn collection_mut(&mut self) -> &mut Collection<Kind> {
|
||||
self.inner.collection_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D, Kind> AsCollectionPage<Kind> for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: AsCollectionPage<Kind>,
|
||||
{
|
||||
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
|
||||
self.inner.collection_page_ref()
|
||||
}
|
||||
|
||||
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
|
||||
self.inner.collection_page_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D, ApInner> AsApActor<ApInner> for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: AsApActor<ApInner>,
|
||||
{
|
||||
fn ap_actor_ref(&self) -> &ApActor<ApInner> {
|
||||
self.inner.ap_actor_ref()
|
||||
}
|
||||
|
||||
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
|
||||
self.inner.ap_actor_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D, Kind> AsActivity<Kind> for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: AsActivity<Kind>,
|
||||
{
|
||||
fn activity_ref(&self) -> &Activity<Kind> {
|
||||
self.inner.activity_ref()
|
||||
}
|
||||
|
||||
fn activity_mut(&mut self) -> &mut Activity<Kind> {
|
||||
self.inner.activity_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D> ActorAndObjectRef for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: ActorAndObjectRef,
|
||||
{
|
||||
fn actor_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.actor_field_ref()
|
||||
}
|
||||
|
||||
fn actor_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.actor_field_mut()
|
||||
}
|
||||
|
||||
fn object_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.object_field_ref()
|
||||
}
|
||||
|
||||
fn object_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.object_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D> TargetRef for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: TargetRef,
|
||||
{
|
||||
fn target_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.target_field_ref()
|
||||
}
|
||||
|
||||
fn target_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.target_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D> OriginRef for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: OriginRef,
|
||||
{
|
||||
fn origin_field_ref(&self) -> &OneOrMany<AnyBase> {
|
||||
self.inner.origin_field_ref()
|
||||
}
|
||||
|
||||
fn origin_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
|
||||
self.inner.origin_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D> OptTargetRef for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: OptTargetRef,
|
||||
{
|
||||
fn target_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
|
||||
self.inner.target_field_ref()
|
||||
}
|
||||
|
||||
fn target_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
|
||||
self.inner.target_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D> OptOriginRef for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: OptOriginRef,
|
||||
{
|
||||
fn origin_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
|
||||
self.inner.origin_field_ref()
|
||||
}
|
||||
|
||||
fn origin_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
|
||||
self.inner.origin_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D> AsQuestion for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: AsQuestion,
|
||||
{
|
||||
fn question_ref(&self) -> &Question {
|
||||
self.inner.question_ref()
|
||||
}
|
||||
|
||||
fn question_mut(&mut self) -> &mut Question {
|
||||
self.inner.question_mut()
|
||||
}
|
||||
}
|
356
src/lib.rs
Normal file
356
src/lib.rs
Normal file
|
@ -0,0 +1,356 @@
|
|||
//! An extension API for activitystreams_new
|
||||
//!
|
||||
//! This crate provides Ext1, Ext2, Ext3, and Ext4 for adding extensions to ActivityStreams types
|
||||
//!
|
||||
//! For an example, we'll implement a PublicKey extension and demonstrate usage with Ext1
|
||||
//!
|
||||
//! ```rust
|
||||
//! use activitystreams_ext::{Ext1, UnparsedExtension};
|
||||
//! use activitystreams_new::{
|
||||
//! actor::{ApActor, Person},
|
||||
//! context,
|
||||
//! prelude::*,
|
||||
//! primitives::XsdAnyUri,
|
||||
//! security,
|
||||
//! unparsed::UnparsedMutExt,
|
||||
//! };
|
||||
//!
|
||||
//! #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
//! #[serde(rename_all = "camelCase")]
|
||||
//! pub struct PublicKey {
|
||||
//! public_key: PublicKeyInner,
|
||||
//! }
|
||||
//!
|
||||
//! #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
//! #[serde(rename_all = "camelCase")]
|
||||
//! pub struct PublicKeyInner {
|
||||
//! id: XsdAnyUri,
|
||||
//! owner: XsdAnyUri,
|
||||
//! public_key_pem: String,
|
||||
//! }
|
||||
//!
|
||||
//! impl<U> UnparsedExtension<U> for PublicKey
|
||||
//! where
|
||||
//! U: UnparsedMutExt,
|
||||
//! {
|
||||
//! type Error = serde_json::Error;
|
||||
//!
|
||||
//! fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
||||
//! Ok(PublicKey {
|
||||
//! public_key: unparsed_mut.remove("publicKey")?,
|
||||
//! })
|
||||
//! }
|
||||
//!
|
||||
//! fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
|
||||
//! unparsed_mut.insert("publicKey", self.public_key)?;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! pub type ExtendedPerson = Ext1<ApActor<Person>, PublicKey>;
|
||||
//!
|
||||
//! fn main() -> Result<(), anyhow::Error> {
|
||||
//! let actor = ApActor::new(
|
||||
//! "http://in.box".parse()?,
|
||||
//! "http://out.box".parse()?,
|
||||
//! Person::new(),
|
||||
//! );
|
||||
//!
|
||||
//! let mut person = Ext1::new(
|
||||
//! actor,
|
||||
//! PublicKey {
|
||||
//! public_key: PublicKeyInner {
|
||||
//! id: "http://key.id".parse()?,
|
||||
//! owner: "http://owner.id".parse()?,
|
||||
//! public_key_pem: "asdfasdfasdf".to_owned(),
|
||||
//! },
|
||||
//! },
|
||||
//! );
|
||||
//!
|
||||
//! person.set_context(context()).add_context(security());
|
||||
//!
|
||||
//! let any_base = person.into_any_base()?;
|
||||
//! println!("any_base: {:#?}", any_base);
|
||||
//! let person = ExtendedPerson::from_any_base(any_base)?;
|
||||
//!
|
||||
//! println!("person: {:#?}", person);
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! ```
|
||||
use activitystreams_new::{
|
||||
base::{Base, Extends},
|
||||
unparsed::{UnparsedMut, UnparsedMutExt},
|
||||
};
|
||||
|
||||
mod ext1;
|
||||
mod ext2;
|
||||
mod ext3;
|
||||
mod ext4;
|
||||
|
||||
/// Transform types from and into the Unparsed structure
|
||||
pub trait UnparsedExtension<U>
|
||||
where
|
||||
U: UnparsedMutExt,
|
||||
{
|
||||
type Error: std::error::Error;
|
||||
|
||||
/// Generate Self from Unparsed
|
||||
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
/// Insert Self into Unparsed
|
||||
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
||||
/// Extend a type with a single value
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Ext1<Inner, A> {
|
||||
#[serde(flatten)]
|
||||
pub ext_one: A,
|
||||
|
||||
/// The type being extended
|
||||
#[serde(flatten)]
|
||||
pub inner: Inner,
|
||||
}
|
||||
|
||||
/// Extend a type with two values
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Ext2<Inner, A, B> {
|
||||
#[serde(flatten)]
|
||||
pub ext_one: A,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub ext_two: B,
|
||||
|
||||
/// The type being extended
|
||||
#[serde(flatten)]
|
||||
pub inner: Inner,
|
||||
}
|
||||
|
||||
/// Extend a type with three values
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Ext3<Inner, A, B, C> {
|
||||
#[serde(flatten)]
|
||||
pub ext_one: A,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub ext_two: B,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub ext_three: C,
|
||||
|
||||
/// The type being extended
|
||||
#[serde(flatten)]
|
||||
pub inner: Inner,
|
||||
}
|
||||
|
||||
/// Extend a type with four values
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct Ext4<Inner, A, B, C, D> {
|
||||
#[serde(flatten)]
|
||||
pub ext_one: A,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub ext_two: B,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub ext_three: C,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub ext_four: D,
|
||||
|
||||
/// The type being extended
|
||||
#[serde(flatten)]
|
||||
pub inner: Inner,
|
||||
}
|
||||
|
||||
impl<Inner, A> Ext1<Inner, A> {
|
||||
pub fn new(inner: Inner, ext_one: A) -> Self {
|
||||
Ext1 { inner, ext_one }
|
||||
}
|
||||
|
||||
pub fn extend<B>(self, ext_two: B) -> Ext2<Inner, A, B> {
|
||||
Ext2 {
|
||||
inner: self.inner,
|
||||
ext_one: self.ext_one,
|
||||
ext_two,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B> Ext2<Inner, A, B> {
|
||||
pub fn new(inner: Inner, ext_one: A, ext_two: B) -> Self {
|
||||
Ext2 {
|
||||
inner,
|
||||
ext_one,
|
||||
ext_two,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extend<C>(self, ext_three: C) -> Ext3<Inner, A, B, C> {
|
||||
Ext3 {
|
||||
inner: self.inner,
|
||||
ext_one: self.ext_one,
|
||||
ext_two: self.ext_two,
|
||||
ext_three,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C> Ext3<Inner, A, B, C> {
|
||||
pub fn new(inner: Inner, ext_one: A, ext_two: B, ext_three: C) -> Self {
|
||||
Ext3 {
|
||||
inner,
|
||||
ext_one,
|
||||
ext_two,
|
||||
ext_three,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extend<D>(self, ext_four: D) -> Ext4<Inner, A, B, C, D> {
|
||||
Ext4 {
|
||||
inner: self.inner,
|
||||
ext_one: self.ext_one,
|
||||
ext_two: self.ext_two,
|
||||
ext_three: self.ext_three,
|
||||
ext_four,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, Kind> Extends<Kind> for Ext1<Inner, A>
|
||||
where
|
||||
Inner: Extends<Kind, Error = serde_json::Error> + UnparsedMut,
|
||||
A: UnparsedExtension<Inner, Error = serde_json::Error>,
|
||||
{
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
|
||||
let mut inner = Inner::extends(base)?;
|
||||
let ext_one = A::try_from_unparsed(&mut inner)?;
|
||||
|
||||
Ok(Ext1 { inner, ext_one })
|
||||
}
|
||||
|
||||
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
|
||||
let Ext1 { mut inner, ext_one } = self;
|
||||
|
||||
ext_one.try_into_unparsed(&mut inner)?;
|
||||
inner.retracts()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, Kind> Extends<Kind> for Ext2<Inner, A, B>
|
||||
where
|
||||
Inner: Extends<Kind, Error = serde_json::Error> + UnparsedMut,
|
||||
A: UnparsedExtension<Inner, Error = serde_json::Error>,
|
||||
B: UnparsedExtension<Inner, Error = serde_json::Error>,
|
||||
{
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
|
||||
let mut inner = Inner::extends(base)?;
|
||||
let ext_one = A::try_from_unparsed(&mut inner)?;
|
||||
let ext_two = B::try_from_unparsed(&mut inner)?;
|
||||
|
||||
Ok(Ext2 {
|
||||
inner,
|
||||
ext_one,
|
||||
ext_two,
|
||||
})
|
||||
}
|
||||
|
||||
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
|
||||
let Ext2 {
|
||||
mut inner,
|
||||
ext_one,
|
||||
ext_two,
|
||||
} = self;
|
||||
|
||||
ext_one.try_into_unparsed(&mut inner)?;
|
||||
ext_two.try_into_unparsed(&mut inner)?;
|
||||
inner.retracts()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, Kind> Extends<Kind> for Ext3<Inner, A, B, C>
|
||||
where
|
||||
Inner: Extends<Kind, Error = serde_json::Error> + UnparsedMut,
|
||||
A: UnparsedExtension<Inner, Error = serde_json::Error>,
|
||||
B: UnparsedExtension<Inner, Error = serde_json::Error>,
|
||||
C: UnparsedExtension<Inner, Error = serde_json::Error>,
|
||||
{
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
|
||||
let mut inner = Inner::extends(base)?;
|
||||
let ext_one = A::try_from_unparsed(&mut inner)?;
|
||||
let ext_two = B::try_from_unparsed(&mut inner)?;
|
||||
let ext_three = C::try_from_unparsed(&mut inner)?;
|
||||
|
||||
Ok(Ext3 {
|
||||
inner,
|
||||
ext_one,
|
||||
ext_two,
|
||||
ext_three,
|
||||
})
|
||||
}
|
||||
|
||||
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
|
||||
let Ext3 {
|
||||
mut inner,
|
||||
ext_one,
|
||||
ext_two,
|
||||
ext_three,
|
||||
} = self;
|
||||
|
||||
ext_one.try_into_unparsed(&mut inner)?;
|
||||
ext_two.try_into_unparsed(&mut inner)?;
|
||||
ext_three.try_into_unparsed(&mut inner)?;
|
||||
inner.retracts()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, A, B, C, D, Kind> Extends<Kind> for Ext4<Inner, A, B, C, D>
|
||||
where
|
||||
Inner: Extends<Kind, Error = serde_json::Error> + UnparsedMut,
|
||||
A: UnparsedExtension<Inner, Error = serde_json::Error>,
|
||||
B: UnparsedExtension<Inner, Error = serde_json::Error>,
|
||||
C: UnparsedExtension<Inner, Error = serde_json::Error>,
|
||||
D: UnparsedExtension<Inner, Error = serde_json::Error>,
|
||||
{
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
|
||||
let mut inner = Inner::extends(base)?;
|
||||
let ext_one = A::try_from_unparsed(&mut inner)?;
|
||||
let ext_two = B::try_from_unparsed(&mut inner)?;
|
||||
let ext_three = C::try_from_unparsed(&mut inner)?;
|
||||
let ext_four = D::try_from_unparsed(&mut inner)?;
|
||||
|
||||
Ok(Ext4 {
|
||||
inner,
|
||||
ext_one,
|
||||
ext_two,
|
||||
ext_three,
|
||||
ext_four,
|
||||
})
|
||||
}
|
||||
|
||||
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
|
||||
let Ext4 {
|
||||
mut inner,
|
||||
ext_one,
|
||||
ext_two,
|
||||
ext_three,
|
||||
ext_four,
|
||||
} = self;
|
||||
|
||||
ext_one.try_into_unparsed(&mut inner)?;
|
||||
ext_two.try_into_unparsed(&mut inner)?;
|
||||
ext_three.try_into_unparsed(&mut inner)?;
|
||||
ext_four.try_into_unparsed(&mut inner)?;
|
||||
inner.retracts()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue