Skip to main content

HostedDep

Trait HostedDep 

Source
pub trait HostedDep:
    Sized
    + Send
    + Sync
    + 'static {
    // Required methods
    fn descriptor(&self) -> Vec<u8> ;
    fn from_descriptor(bytes: &[u8]) -> Self;
}
Expand description

User-facing trait that opts a dependency value into the Hosted sharing strategy. Like CloneableDep, but the owner instance lives in the parent test runner process for the entire suite. The parent runs the constructor once per Hosted dep and keeps the value alive until every worker has finished — useful for singleton services like an in-process TCP listener, a Docker container, an env-based test environment, or any long-running runtime that must not be duplicated across worker processes.

The parent calls descriptor on its owner once and forwards the resulting bytes to every worker over IPC. Each worker reconstructs a local handle via from_descriptor — the handle typically connects to the live owner held by the parent (e.g. opens a TCP connection to the address carried in the descriptor).

For descriptor-based Hosted deps, the owner and worker handle share the same type Self. The implementation is responsible for stashing owner-only state (sockets, background threads, etc.) in fields that the worker side won’t touch.

Required Methods§

Source

fn descriptor(&self) -> Vec<u8>

Owner-side: produce the descriptor bytes that workers will use to reconstruct a connected handle.

Source

fn from_descriptor(bytes: &[u8]) -> Self

Worker-side: reconstruct a handle from descriptor bytes received from the parent.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§