#activity-stream #activity-pub

activitystreams-ext

ActivityStreams 库的扩展类型

4 个版本

0.1.0-alpha.32022年12月7日
0.1.0-alpha.22020年7月26日
0.1.0-alpha.02020年7月25日

#4 in #activitypub

Download history 26/week @ 2024-03-11 45/week @ 2024-03-18 77/week @ 2024-03-25 55/week @ 2024-04-01 31/week @ 2024-04-08 22/week @ 2024-04-15 32/week @ 2024-04-22 23/week @ 2024-04-29 15/week @ 2024-05-06 18/week @ 2024-05-13 26/week @ 2024-05-20 13/week @ 2024-05-27 15/week @ 2024-06-03 29/week @ 2024-06-10 69/week @ 2024-06-17 31/week @ 2024-06-24

146 每月下载量
用于 ap-relay

GPL-3.0 许可证

41KB
1K SLoC

ActivityStreams Ext

此包提供了 Ext1、Ext2、Ext3 和 Ext4,用于向 ActivityStreams 类型添加扩展

用法

首先,将 ActivityStreams 添加到您的依赖项中

[dependencies]
activitystreams = "0.7.0-alpha.3"
activitystreams-ext = "0.1.0-alpha.2"

例如,我们将实现一个 PublicKey 扩展,并使用 Ext1 展示其用法

use activitystreams::{
    actor::{ApActor, Person},
    context,
    prelude::*,
    security,
    unparsed::UnparsedMutExt,
    url::Url,
};
use activitystreams_ext::{Ext1, UnparsedExtension};

#[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: Url,
    owner: Url,
    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()?, 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(())
}

贡献

如果您发现任何问题,请随时提交问题。请注意,任何贡献的代码都将根据 GPLv3 许可证进行许可。

许可证

版权所有 © 2020 Riley Trautman

ActivityStreams 是免费软件:您可以根据自由软件基金会发布的 GNU 通用公共许可证的条款重新分配和/或修改它,许可证版本为 3,或者(根据您的选择)任何更高版本。

ActivityStreams 是希望对您有用的,但没有任何保证;甚至没有关于其商业性或针对特定目的的适用性的暗示性保证。有关详细信息,请参阅 GNU 通用公共许可证。此文件是 ActivityStreams 的一部分。

您应该已经收到了 ActivityStreams 一起的 GNU 通用公共许可证副本。如果没有,请参阅 https://gnu.ac.cn/licenses/

依赖项

~2.4–3.5MB
~62K SLoC