pub struct ContextBuilder { /* private fields */ }Expand description
Builder for creating Context instances with fluent API
Provides a more ergonomic way to create contexts with various configurations.
§Example
use mecha10::context::ContextBuilder;
let ctx = ContextBuilder::new("my-node")
.with_instance("instance-1")
.with_redis("redis://localhost:6379")
.build()
.await?;Implementations§
Source§impl ContextBuilder
impl ContextBuilder
Sourcepub fn with_instance(self, instance: impl Into<String>) -> Self
pub fn with_instance(self, instance: impl Into<String>) -> Self
Set an instance name for this context
Allows running multiple instances of the same node with different names. The final node_id becomes “{node_name}/{instance}”.
§Example
let builder = ContextBuilder::new("camera")
.with_instance("left");Sourcepub fn with_redis(self, url: impl Into<String>) -> Self
pub fn with_redis(self, url: impl Into<String>) -> Self
Set the Redis connection URL
Override the default Redis URL from environment or config.
§Example
let builder = ContextBuilder::new("my-node")
.with_redis("redis://localhost:6379");Sourcepub fn with_state_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn with_state_dir(self, dir: impl Into<PathBuf>) -> Self
Set the state directory for persistent storage
§Example
let builder = ContextBuilder::new("my-node")
.with_state_dir("./data/state");Sourcepub fn with_custom_redis<F>(self, configure: F) -> Selfwhere
F: FnOnce(&mut RedisConfig),
pub fn with_custom_redis<F>(self, configure: F) -> Selfwhere
F: FnOnce(&mut RedisConfig),
Configure Redis with custom settings
Provides a callback to customize Redis configuration.
§Example
let builder = ContextBuilder::new("my-node")
.with_custom_redis(|cfg| {
cfg.url = "redis://custom:6379".to_string();
cfg.max_connections = 20;
cfg.timeout_ms = 5000;
});Source§impl ContextBuilder
impl ContextBuilder
Sourcepub fn local_dev(node_id: impl Into<String>) -> Self
pub fn local_dev(node_id: impl Into<String>) -> Self
Create a local development context
Pre-configured for local development:
- Redis at localhost:6379
- State directory at ./data/state
- Relaxed timeouts
§Example
let ctx = ContextBuilder::local_dev("my-node")
.build()
.await?;Sourcepub fn production(node_id: impl Into<String>) -> Self
pub fn production(node_id: impl Into<String>) -> Self
Create a production context
Pre-configured for production:
- Redis from environment variable
- State directory from environment or /var/lib/mecha10
- Strict timeouts
- Connection pooling
§Example
let ctx = ContextBuilder::production("my-node")
.build()
.await?;Trait Implementations§
Source§impl Clone for ContextBuilder
impl Clone for ContextBuilder
Source§fn clone(&self) -> ContextBuilder
fn clone(&self) -> ContextBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ContextBuilder
impl RefUnwindSafe for ContextBuilder
impl Send for ContextBuilder
impl Sync for ContextBuilder
impl Unpin for ContextBuilder
impl UnwindSafe for ContextBuilder
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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