From f4b0a7c5159d418e22682d2bd7d413fb3587ca7f Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 19:51:52 +0100 Subject: store function accept any document --- src/swarm/members.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/swarm') diff --git a/src/swarm/members.rs b/src/swarm/members.rs index 8d7f909..9885750 100644 --- a/src/swarm/members.rs +++ b/src/swarm/members.rs @@ -21,9 +21,9 @@ use std::time::Duration; use serde_json::{Value as JsonValue, json}; use tracing::{debug, info, warn}; -use crate::document::Document; use crate::document::meta; use crate::document::store::{self, StoreError}; +use crate::document::{Document, Transactable}; use crate::state::AppState; pub(crate) fn members_dir() -> Vec { @@ -74,7 +74,11 @@ pub(crate) fn tier(doc: &Document, pk: &str) -> Tier { } } -pub(crate) fn set_tier(doc: &mut Document, pk: &str, tier: Tier) -> Result<(), StoreError> { +pub(crate) fn set_tier( + doc: &mut impl Transactable, + pk: &str, + tier: Tier, +) -> Result<(), StoreError> { store::write_path(doc, &tier_path(pk), &json!(tier.as_str())) } @@ -100,7 +104,7 @@ pub(crate) fn aliases(doc: &Document) -> HashMap { .collect() } -fn set_alias(doc: &mut Document, pk: &str, alias: Option<&str>) -> Result<(), StoreError> { +fn set_alias(doc: &mut impl Transactable, pk: &str, alias: Option<&str>) -> Result<(), StoreError> { match alias { Some(alias) => store::write_path(doc, &alias_path(pk), &json!(alias)), None => match store::delete_path(doc, &alias_path(pk), false) { @@ -314,7 +318,7 @@ pub(crate) async fn ensure_registered(state: &AppState) { } /// Removes `pk`'s entry (an operator forgot it). Absent is fine. -pub(crate) fn unregister(doc: &mut Document, pk: &str) -> Result<(), StoreError> { +pub(crate) fn unregister(doc: &mut impl Transactable, pk: &str) -> Result<(), StoreError> { match store::delete_path(doc, &member_path(pk), false) { Err(StoreError::NotFound) => Ok(()), result => result, -- cgit v1.3.1