engine.rs (2362B)
1 use std::sync::Arc; 2 3 use radroots_signing::Signer; 4 use radroots_transport::{EventSink, EventSource}; 5 6 use crate::policy::{Clock, DeadlinePolicy, EngineBuilder, IdSource, SyncStorage}; 7 8 /// Injected, executor-neutral synchronization composition boundary. 9 #[derive(Clone)] 10 pub struct Engine { 11 pub(crate) storage: Arc<dyn SyncStorage>, 12 pub(crate) source: Option<Arc<dyn EventSource>>, 13 pub(crate) sink: Option<Arc<dyn EventSink>>, 14 pub(crate) signer: Option<Arc<dyn Signer>>, 15 pub(crate) clock: Arc<dyn Clock>, 16 pub(crate) ids: Arc<dyn IdSource>, 17 pub(crate) deadlines: DeadlinePolicy, 18 } 19 20 impl Engine { 21 /// Starts an explicit capability builder around required host policies. 22 pub fn builder( 23 storage: Arc<dyn SyncStorage>, 24 clock: Arc<dyn Clock>, 25 ids: Arc<dyn IdSource>, 26 deadlines: DeadlinePolicy, 27 ) -> EngineBuilder { 28 EngineBuilder::new(storage, clock, ids, deadlines) 29 } 30 31 /// Returns the canonical storage capability. 32 pub fn storage(&self) -> &dyn SyncStorage { 33 self.storage.as_ref() 34 } 35 36 /// Returns the configured event source, when pull is enabled. 37 pub fn source(&self) -> Option<&dyn EventSource> { 38 self.source.as_deref() 39 } 40 41 /// Returns the configured event sink, when delivery is enabled. 42 pub fn sink(&self) -> Option<&dyn EventSink> { 43 self.sink.as_deref() 44 } 45 46 /// Returns the configured signer, when outbound authoring is enabled. 47 pub fn signer(&self) -> Option<&dyn Signer> { 48 self.signer.as_deref() 49 } 50 51 /// Returns the injected clock policy. 52 pub fn clock(&self) -> &dyn Clock { 53 self.clock.as_ref() 54 } 55 56 /// Returns the injected operation identity source. 57 pub fn ids(&self) -> &dyn IdSource { 58 self.ids.as_ref() 59 } 60 61 /// Returns the bounded deadline policy. 62 pub const fn deadlines(&self) -> DeadlinePolicy { 63 self.deadlines 64 } 65 } 66 67 impl core::fmt::Debug for Engine { 68 fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 69 formatter 70 .debug_struct("Engine") 71 .field("source", &self.source.is_some()) 72 .field("sink", &self.sink.is_some()) 73 .field("signer", &self.signer.is_some()) 74 .field("deadlines", &self.deadlines) 75 .finish_non_exhaustive() 76 } 77 }