pub struct HostedRpcOwnerCell { /* private fields */ }Expand description
Type-erased, parent-owned cell that holds the owner value behind a
Mutex and exposes a &self dispatch entry point. Constructed by the
macro-generated registration code on the parent (the DependencyConstructor
for a HostedRpc dep returns one of these wrapped in Arc<dyn Any>)
and kept alive in _hosted_owners for the suite’s lifetime.
Two internal variants:
Syncholds aHostedRpcDepdispatcher and supports the legacy synchronous dispatch path. The sync runtime uses this exclusively.Asyncholds anAsyncHostedRpcDepdispatcher behind atokio::sync::Mutexso awaits inside the dispatcher don’t block other tokio tasks waiting for the lock. The tokio runtime constructs this variant for HostedRpc registrations.
Implementations§
Source§impl HostedRpcOwnerCell
impl HostedRpcOwnerCell
Sourcepub fn from_owner<T>(owner: T) -> HostedRpcOwnerCellwhere
T: HostedRpcDep,
pub fn from_owner<T>(owner: T) -> HostedRpcOwnerCellwhere
T: HostedRpcDep,
Wrap a synchronous owner value into a HostedRpcOwnerCell. The owner
type must implement HostedRpcDep. This is the back-compat
constructor used by the sync runtime and by any manual hand-written
fixture; the runtime never blocks on async dispatch through cells
built this way.
Sourcepub fn from_async_owner<T>(owner: T) -> HostedRpcOwnerCellwhere
T: AsyncHostedRpcDep,
pub fn from_async_owner<T>(owner: T) -> HostedRpcOwnerCellwhere
T: AsyncHostedRpcDep,
Wrap an owner value that exposes an async dispatcher into a
HostedRpcOwnerCell. Accepts any AsyncHostedRpcDep — including
every HostedRpcDep via the blanket bridge — so the tokio runtime
can route both sync and async owners through one async dispatch path.
Sourcepub fn dispatch(&self, method_idx: u32, args: &[u8]) -> Result<Vec<u8>, String>
pub fn dispatch(&self, method_idx: u32, args: &[u8]) -> Result<Vec<u8>, String>
Dispatch one method call synchronously. Catches owner panics and
turns them into Err("hosted rpc owner panicked: …") so the
dispatcher loop never dies. The lock is acquired inside the
catch_unwind closure on purpose: when the owner panics, the
MutexGuard drops during the unwind, which poisons the mutex.
Every subsequent dispatch call then short-circuits with the
stable "hosted rpc owner poisoned" error and does NOT retry the
(possibly half-mutated) owner.
For cells constructed via Self::from_async_owner, synchronous
dispatch is unsupported and the call returns
Err("hosted rpc owner cell uses the async dispatch path; use dispatch_async or dispatch_blocking").
Note that under the tokio feature a plain HostedRpcDep owner may
also end up in the async cell variant via the blanket bridge, so
this branch is not strictly limited to user-authored async owners.
The sync runtime never builds async cells, so this branch only
fires in misuse cases.
Sourcepub async fn dispatch_async(
&self,
method_idx: u32,
args: &[u8],
) -> Result<Vec<u8>, String>
pub async fn dispatch_async( &self, method_idx: u32, args: &[u8], ) -> Result<Vec<u8>, String>
Async dispatch entry point used by the tokio runtime’s parent-side
HostedRpc loop and by the in-process transport’s block_on bridge.
Works for both Sync and Async cell variants:
Syncvariant: invokes the synchronous dispatcher inline (noawaitactually happens).Asyncvariant: awaits the user’s async dispatcher with panic capture so anawait-side panic poisons the cell.
Sourcepub fn dispatch_blocking(
&self,
method_idx: u32,
args: &[u8],
) -> Result<Vec<u8>, String>
pub fn dispatch_blocking( &self, method_idx: u32, args: &[u8], ) -> Result<Vec<u8>, String>
Synchronous bridge to Self::dispatch_async for sync call sites
(such as InProcessHostedRpcTransport::call) that need to feed
an async owner cell. Drives the future with
tokio::task::block_in_place + tokio::runtime::Handle::block_on
when an async cell is present, and falls back to the regular sync
dispatch otherwise.
Sync cells short-circuit through the regular sync path with no
runtime requirement. Async cells require a running multi-thread
Tokio runtime, matching the IPC transport’s existing requirement.