pub struct ModuleBootstrap {
pub module_id: String,
pub socket_path: PathBuf,
pub data_dir: PathBuf,
}Expand description
Bootstrap parameters for a module, read from environment.
The node sets these when spawning. For standalone testing, set them manually:
MODULE_ID, SOCKET_PATH, DATA_DIR.
Fields§
§module_id: String§socket_path: PathBuf§data_dir: PathBufImplementations§
Source§impl ModuleBootstrap
impl ModuleBootstrap
Sourcepub fn from_env() -> Result<Self, VarError>
pub fn from_env() -> Result<Self, VarError>
Read bootstrap params from environment.
Expects: MODULE_ID, SOCKET_PATH, DATA_DIR.
Sourcepub fn from_env_or_defaults(
module_id: impl Into<String>,
socket_path: impl Into<PathBuf>,
data_dir: impl Into<PathBuf>,
) -> Self
pub fn from_env_or_defaults( module_id: impl Into<String>, socket_path: impl Into<PathBuf>, data_dir: impl Into<PathBuf>, ) -> Self
Bootstrap from env, or use defaults when env vars are unset (standalone/testing).
Sourcepub fn for_module(module_name: &str) -> Self
pub fn for_module(module_name: &str) -> Self
Bootstrap from env, or defaults derived from module name (standalone/testing).
Uses data/modules/{name}.sock and data/modules/{name} when env vars are unset.
Sourcepub fn init_module(module_name: &str) -> Self
pub fn init_module(module_name: &str) -> Self
Init logging, set DATA_DIR, log startup, and return bootstrap. One-liner for module mains.
Sourcepub fn context(
&self,
data_dir: &Path,
config: HashMap<String, String>,
) -> ModuleContext
pub fn context( &self, data_dir: &Path, config: HashMap<String, String>, ) -> ModuleContext
Build ModuleContext from bootstrap + data_dir + config (reduces setup boilerplate).
Sourcepub fn context_with_config<C: ModuleConfig>(
&self,
data_dir: &Path,
) -> (ModuleContext, C)
pub fn context_with_config<C: ModuleConfig>( &self, data_dir: &Path, ) -> (ModuleContext, C)
Load config from {data_dir}/config.toml and build ModuleContext. Convention for setup closures.
Trait Implementations§
Source§impl Clone for ModuleBootstrap
impl Clone for ModuleBootstrap
Source§fn clone(&self) -> ModuleBootstrap
fn clone(&self) -> ModuleBootstrap
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ModuleBootstrap
impl RefUnwindSafe for ModuleBootstrap
impl Send for ModuleBootstrap
impl Sync for ModuleBootstrap
impl Unpin for ModuleBootstrap
impl UnsafeUnpin for ModuleBootstrap
impl UnwindSafe for ModuleBootstrap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more