Struct ServiceToImport

Source
pub struct ServiceToImport<T: ?Sized + Service> { /* private fields */ }
Expand description

A special wrapper of handle, used to import a service.

You can make an instance of this into any smart pointer of a trait object as far as the trait is a subtrait of Service and marked with the macro service.

The only way to actually import a ServiceToImport is either

  1. Receiving it as a return value, in a remote call
  2. Receiving as an argument while a method in handling another service

ServiceToImport is a compatible type with ServiceToExport and ServiceRef You can export a service object by putting one of those two types on the same place on the server side. See Service Compatibility section for more.

ServiceToImport is a wrapper of HandleToExchange that hides the detail exchange process. However you don’t have to know what HandleToExchange is, unless you’re going to perform raw export and import.

NOTE: it implements Deserialize, but you must NEVER try to deserialize it. It has a side effect of registering the handle in the context, and so should be called only by remote-trait-object’s internal process.

§Example

use remote_trait_object::*;
use std::sync::Arc;
use parking_lot::RwLock;

#[service(no_skeleton)]
pub trait Hello: Service {
    fn hello(&self) -> Vec<ServiceToImport<dyn Hello>>;
}

fn do_some_imports(x: Box<dyn Hello>) {
    let mut v = x.hello();
    let a: Box<dyn Hello> = v.pop().unwrap().into_proxy();
    let b: Arc<dyn Hello> = v.pop().unwrap().into_proxy();
    let c: Arc<RwLock<dyn Hello>> = v.pop().unwrap().into_proxy();
}

Implementations§

Source§

impl<T: ?Sized + Service> ServiceToImport<T>

Source

pub fn into_proxy<P: ImportProxy<T>>(self) -> P

Converts itself into a smart pointer of the trait, which is a proxy object.

Source

pub fn cast_service<U: ?Sized + Service>(self) -> Result<ServiceToImport<U>, ()>

Casts into another ServiceToImport with a different service trait.

If the target trait is not compatible with the original one, it returns Err.

See Service Compatiblity section for more.

Source

pub fn cast_service_without_compatibility_check<U: ?Sized + Service>( self, ) -> ServiceToImport<U>

Casts into another ServiceToImport with a different service trait, without check.

If the target trait is not compatible with the original one, any method call of the proxy object imported with this will cause a serious error.

See Service Compatiblity section for more.

Trait Implementations§

Source§

impl<'de, T: ?Sized + Service> Deserialize<'de> for ServiceToImport<T>

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ServiceToImport<T>
where T: ?Sized,

§

impl<T> !RefUnwindSafe for ServiceToImport<T>

§

impl<T> Send for ServiceToImport<T>
where T: ?Sized,

§

impl<T> Sync for ServiceToImport<T>
where T: ?Sized,

§

impl<T> Unpin for ServiceToImport<T>
where T: Unpin + ?Sized,

§

impl<T> !UnwindSafe for ServiceToImport<T>

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,