Skip to main content

Service

Struct Service 

Source
pub struct Service<E> { /* private fields */ }
Expand description

A typed service. Methods execute once; only the portable entrypoint invokes serde.

Implementations§

Source§

impl<E: 'static> Service<E>

Source

pub fn new( name: impl Into<String>, create: impl Fn(Declaration) -> Result<E> + 'static, ) -> Self

Create a native declaration with explicit identity and default options.

Source

pub fn before_create<P, F, Fut>(self, prepare: F) -> Self
where P: 'static, F: Fn() -> Fut + 'static, Fut: Future<Output = Result<P>> + 'static,

Wait for an adapter’s executor before running the synchronous declaration factory.

Source

pub fn signature(self, signature: Option<String>) -> Self

Declare the canonical ABI signature used by typed dependency admission.

Source

pub fn contract(self, binding: impl Into<String>, prepared: &[u8]) -> Self

Decode the service’s immutable WIT once for RPC validation before provider execution.

Source

pub fn lifetime(self, lifetime: Lifetime, linger_ms: u32) -> Self

Set the ownership policy and optional idle retention period.

Source

pub fn method<A, R, F, Fut>(self, name: impl Into<String>, handle: F) -> Self
where A: DeserializeOwned + 'static, R: Serialize + 'static, F: Fn(Rc<E>, Context, A) -> Fut + 'static, Fut: Future<Output = Result<R>> + 'static,

Bind one callback to typed local and portable entrypoints.

Source

pub fn method_with<A, R, F, Fut>( self, name: impl Into<String>, handle: F, codec: Codec<A, R>, ) -> Self
where A: 'static, R: 'static, F: Fn(Rc<E>, Context, A) -> Fut + 'static, Fut: Future<Output = Result<R>> + 'static,

Bind one callback to a typed local entrypoint, as Service::method does, and to a portable entrypoint that reads the arguments and writes the result with codec instead of serde. Local calls never run the codec.

Source§

impl<E: 'static> Service<E>

Source

pub fn local_method<A, R, F, Fut>( self, name: impl Into<String>, handle: F, ) -> Self
where A: 'static, R: 'static, F: Fn(Rc<E>, Context, A) -> Fut + 'static, Fut: Future<Output = Result<R>> + 'static,

Bind a host-local callback with typed Rust values and no portable entrypoint.

The method exists only for callers in this process that hold the exact argument type, such as an executor’s lifecycle adapter carrying owned host resources. Every portable access (call_portable, Host::invoke_portable, foreign hosts and isolated Orb references) is refused with Reason::LocalValue before the callback runs; no serde conversion is ever attempted.

Source§

impl<E: 'static> Service<E>

Source

pub fn payload_method<F, Fut, R>( self, name: impl Into<String>, handle: F, ) -> Self
where F: Fn(Rc<E>, Context, Payload) -> Fut + 'static, Fut: Future<Output = Result<R>> + 'static, R: Into<Outcome> + 'static,

Bind a portable-only callback that receives and returns the whole Payload, including host-issued capabilities. It is the entrypoint for executors that issue resources. It has no typed local entrypoint, so crate::Reference::call refuses it.

The callback returns a Payload, or an Outcome when the call keeps physically working after its result (a stream’s producer, for example).

Auto Trait Implementations§

§

impl<E> !RefUnwindSafe for Service<E>

§

impl<E> !Send for Service<E>

§

impl<E> !Sync for Service<E>

§

impl<E> !UnwindSafe for Service<E>

§

impl<E> Forget for Service<E>

§

impl<E> Freeze for Service<E>
where PhantomData<E>: Freeze,

§

impl<E> Move for Service<E>

§

impl<E> Unpin for Service<E>
where PhantomData<E>: Unpin,

§

impl<E> UnsafeUnpin for Service<E>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.