[][src]Struct remote_trait_object::ServiceToImport

pub struct ServiceToImport<T: ?Sized + Service> { /* fields omitted */ }

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

impl<T: ?Sized + Service> ServiceToImport<T>[src]

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

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

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

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.

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

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

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

Auto Trait Implementations

impl<T> !RefUnwindSafe for ServiceToImport<T>

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

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

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

impl<T> !UnwindSafe for ServiceToImport<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.