activitystreams-ext's temporary home
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3.5 KiB

ActivityStreams Ext

This crate provides Ext1, Ext2, Ext3, and Ext4 for adding extensions to ActivityStreams types


First, add ActivityStreams to your dependencies

activitystreams-new = { git = "", branch = "main" }
activitystreams-ext = { git = "", branch = "main" }

For an example, we'll implement a PublicKey extension and demonstrate usage with Ext1

use activitystreams_ext::{Ext1, UnparsedExtension};
use activitystreams_new::{
    actor::{ApActor, Person},

#[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
    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)?;

pub type ExtendedPerson = Ext1<ApActor<Person>, PublicKey>;

fn main() -> Result<(), anyhow::Error> {
    let actor = ApActor::new(

    let mut person = Ext1::new(
        PublicKey {
            public_key: PublicKeyInner {
                id: "".parse()?,
                owner: "".parse()?,
                public_key_pem: "asdfasdfasdf".to_owned(),


    let any_base = person.into_any_base()?;
    println!("any_base: {:#?}", any_base);
    let person = ExtendedPerson::from_any_base(any_base)?;

    println!("person: {:#?}", person);


Feel free to open issues for anything you find an issue with. Please note that any contributed code will be licensed under the GPLv3.


Copyright © 2020 Riley Trautman

ActivityStreams is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

ActivityStreams is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This file is part of ActivityStreams.

You should have received a copy of the GNU General Public License along with ActivityStreams. If not, see