Skip to main content

HostedRpcOwnerCell

Struct HostedRpcOwnerCell 

Source
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:

  • Sync holds a HostedRpcDep dispatcher and supports the legacy synchronous dispatch path. The sync runtime uses this exclusively.
  • Async holds an AsyncHostedRpcDep dispatcher behind a tokio::sync::Mutex so 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

Source

pub fn from_owner<T: HostedRpcDep>(owner: T) -> Self

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.

Source

pub fn from_async_owner<T: AsyncHostedRpcDep>(owner: T) -> Self

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.

Source

pub fn from_shared_owner_sync<T, F>(owner: Arc<T>, dispatch: F) -> Self
where T: Send + Sync + 'static, F: Fn(&T, u32, &[u8]) -> Result<Vec<u8>, String> + Send + Sync + 'static,

Construct a synchronous HostedRpcOwnerCell that dispatches against &T borrowed from a shared Arc<T>, rather than consuming T outright. Used exclusively by the #[test_dep(scope = Hosted, worker = both(Trait))] lowering so the parent-side dep map can hand the same Arc<T> to downstream consumers that take &T while the RPC view keeps dispatching to the same owner instance.

The supplied dispatch closure is typically a thin wrapper around the #[hosted_rpc]-generated dispatch_<snake>_shared(&T, method_idx, args) helper.

Calls remain serialized by the cell’s internal Mutex, matching the existing Self::from_owner semantics.

Source

pub fn from_shared_owner_async<T, F>(owner: Arc<T>, dispatch: F) -> Self
where T: Send + Sync + 'static, F: for<'a> Fn(&'a T, u32, &'a [u8]) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, String>> + Send + 'a>> + Send + Sync + 'static,

Async counterpart of Self::from_shared_owner_sync for the tokio runtime: dispatch against &T via an async closure that returns a boxed future. Used by the worker = both(Trait) lowering when an async owner constructor is in play, or when the trait declared async fn methods.

Calls remain serialized by the async cell’s tokio::sync::Mutex, matching the existing Self::from_async_owner semantics.

Source

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.

Source

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:

  • Sync variant: invokes the synchronous dispatcher inline (no await actually happens).
  • Async variant: awaits the user’s async dispatcher with panic capture so an await-side panic poisons the cell.
Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.