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
- Receiving it as a return value, in a remote call
- 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>
impl<T: ?Sized + Service> ServiceToImport<T>
Sourcepub fn into_proxy<P: ImportProxy<T>>(self) -> P
pub fn into_proxy<P: ImportProxy<T>>(self) -> P
Converts itself into a smart pointer of the trait, which is a proxy object.
Sourcepub fn cast_service<U: ?Sized + Service>(self) -> Result<ServiceToImport<U>, ()>
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.
Sourcepub fn cast_service_without_compatibility_check<U: ?Sized + Service>(
self,
) -> ServiceToImport<U>
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.