pub struct Context { /* private fields */ }Expand description
Execution context provided to nodes during execution.
The context provides access to:
- Arena for reading/writing data
- Pipeline configuration
- Trace metadata
- Logging and metrics
- External providers (clock, HTTP, RNG, etc.)
§Providers
The context includes pluggable providers for external dependencies, enabling deterministic testing by mocking these dependencies.
In production, real providers are used automatically. In tests,
use TestContext or the with_providers() constructor to inject mocks.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(
trace_id: TraceId,
node_id: NodeId,
reader: ArenaReader,
writer: ArenaWriter,
wal: Arc<Wal>,
) -> Self
pub fn new( trace_id: TraceId, node_id: NodeId, reader: ArenaReader, writer: ArenaWriter, wal: Arc<Wal>, ) -> Self
Create a new execution context with default (real) providers.
Sourcepub fn with_providers(
trace_id: TraceId,
node_id: NodeId,
reader: ArenaReader,
writer: ArenaWriter,
wal: Arc<Wal>,
clock: Arc<dyn ClockProvider>,
http: Arc<dyn HttpProvider>,
rng: Arc<dyn RngProvider>,
uuid: Arc<dyn UuidProvider>,
fs: Arc<dyn FsProvider>,
env: Arc<dyn EnvProvider>,
secrets: Arc<dyn SecretsProvider>,
) -> Self
pub fn with_providers( trace_id: TraceId, node_id: NodeId, reader: ArenaReader, writer: ArenaWriter, wal: Arc<Wal>, clock: Arc<dyn ClockProvider>, http: Arc<dyn HttpProvider>, rng: Arc<dyn RngProvider>, uuid: Arc<dyn UuidProvider>, fs: Arc<dyn FsProvider>, env: Arc<dyn EnvProvider>, secrets: Arc<dyn SecretsProvider>, ) -> Self
Create a new execution context with custom providers.
This is primarily used for testing to inject mock providers.
Sourcepub fn read_bytes(&self, ptr: RelPtr<()>) -> Result<Vec<u8>>
pub fn read_bytes(&self, ptr: RelPtr<()>) -> Result<Vec<u8>>
Read bytes from the arena using a relative pointer.
Sourcepub fn write_bytes(&self, bytes: &[u8]) -> Result<RelPtr<()>>
pub fn write_bytes(&self, bytes: &[u8]) -> Result<RelPtr<()>>
Write bytes to the arena and return a relative pointer.
Sourcepub fn read_raw(&self, offset: ArenaOffset, size: usize) -> Result<Vec<u8>>
pub fn read_raw(&self, offset: ArenaOffset, size: usize) -> Result<Vec<u8>>
Read raw bytes from the arena at a specific offset.
Sourcepub fn write_position(&self) -> ArenaOffset
pub fn write_position(&self) -> ArenaOffset
Get the current write position in the arena.
Sourcepub fn clock(&self) -> &dyn ClockProvider
pub fn clock(&self) -> &dyn ClockProvider
Get the clock provider.
Sourcepub fn http(&self) -> &dyn HttpProvider
pub fn http(&self) -> &dyn HttpProvider
Get the HTTP provider.
Sourcepub fn rng(&self) -> &dyn RngProvider
pub fn rng(&self) -> &dyn RngProvider
Get the RNG provider.
Sourcepub fn uuid_provider(&self) -> &dyn UuidProvider
pub fn uuid_provider(&self) -> &dyn UuidProvider
Get the UUID provider.
Sourcepub fn fs(&self) -> &dyn FsProvider
pub fn fs(&self) -> &dyn FsProvider
Get the filesystem provider.
Sourcepub fn env_provider(&self) -> &dyn EnvProvider
pub fn env_provider(&self) -> &dyn EnvProvider
Get the environment provider.
Sourcepub fn secrets(&self) -> &dyn SecretsProvider
pub fn secrets(&self) -> &dyn SecretsProvider
Get the secrets provider.
Sourcepub fn system_time_millis(&self) -> u64
pub fn system_time_millis(&self) -> u64
Get current system time in milliseconds since UNIX epoch.
Sourcepub fn random_u64(&self) -> u64
pub fn random_u64(&self) -> u64
Generate a random u64.
Sourcepub fn random_f64(&self) -> f64
pub fn random_f64(&self) -> f64
Generate a random f64 in [0, 1).
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> 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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.