Skip to main content

coven_storage/
publication.rs

1//! Per-request publication authority supplied by the synchronization owner.
2use crate::{ObjectPath, StorageError};
3use std::sync::Arc;
4
5/// Re-evaluates the installation's authority immediately before a native request.
6/// This capability carries no provider IO and must include elapsed sleep time.
7pub trait PublicationGate: Send + Sync {
8    /// Refuse without sending when this path cannot currently be published.
9    fn check(&self, path: &ObjectPath) -> Result<(), StorageError>;
10}
11
12/// One destination and its shared gate, retained through native waits and retries.
13#[derive(Clone)]
14pub struct PublicationRequest {
15    gate: Arc<dyn PublicationGate>,
16    path: ObjectPath,
17}
18impl PublicationRequest {
19    pub(crate) fn new(gate: Arc<dyn PublicationGate>, path: ObjectPath) -> Self {
20        Self { gate, path }
21    }
22    /// Check again after waiting for credentials or a transfer permit, directly
23    /// before starting the provider request. Success grants no reusable permit.
24    pub fn check(&self) -> Result<(), StorageError> {
25        self.gate.check(&self.path)
26    }
27}
28impl std::fmt::Debug for PublicationRequest {
29    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30        f.debug_struct("PublicationRequest").field("path", &self.path).finish_non_exhaustive()
31    }
32}