From f4db94db27e68f091dcf05334506f7a341849642 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 20 May 2024 02:39:23 +0200 Subject: [PATCH] feat(apb): optional Send marker on Base, on by default --- apb/Cargo.toml | 3 ++- apb/src/macros.rs | 12 ++++++++++++ apb/src/types/base.rs | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apb/Cargo.toml b/apb/Cargo.toml index fce7a037..1618763b 100644 --- a/apb/Cargo.toml +++ b/apb/Cargo.toml @@ -24,13 +24,14 @@ sea-orm = { version = "0.12", optional = true } reqwest = { version = "0.12", features = ["json"], optional = true } [features] -default = ["activitypub-miscellaneous-terms"] +default = ["activitypub-miscellaneous-terms", "send"] # extensions activitypub-miscellaneous-terms = [] # https://swicg.github.io/miscellany/ activitypub-counters = [] # https://ns.alemi.dev/as/counters/# activitypub-fe = [] # https://ns.alemi.dev/as/fe/# litepub = [] # incomplete, https://litepub.social/ # builtin utils +send = [] orm = ["dep:sea-orm"] fetch = ["dep:reqwest"] # providers diff --git a/apb/src/macros.rs b/apb/src/macros.rs index f797b37b..3a46c59a 100644 --- a/apb/src/macros.rs +++ b/apb/src/macros.rs @@ -1,3 +1,15 @@ +#[cfg(feature = "send")] +pub trait MaybeSend : Send {} +#[cfg(feature = "send")] +impl MaybeSend for T {} + + +#[cfg(not(feature = "send"))] +pub trait MaybeSend {} +#[cfg(not(feature = "send"))] +impl MaybeSend for T {} + + #[derive(Debug, thiserror::Error)] #[error("invalid type value")] pub struct TypeValueError; diff --git a/apb/src/types/base.rs b/apb/src/types/base.rs index ee78e707..e992435c 100644 --- a/apb/src/types/base.rs +++ b/apb/src/types/base.rs @@ -8,13 +8,13 @@ crate::strenum! { }; } -pub trait Base { +pub trait Base : crate::macros::MaybeSend { fn id(&self) -> Option<&str> { None } fn base_type(&self) -> Option { None } } -pub trait BaseMut { +pub trait BaseMut : crate::macros::MaybeSend { fn set_id(self, val: Option<&str>) -> Self; fn set_base_type(self, val: Option) -> Self; }