[−][src]Struct remote_trait_object::ServiceToImport
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
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]
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
impl<'de, T: ?Sized + Service> Deserialize<'de> for ServiceToImport<T>
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
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,
T: Unpin,
impl<T> !UnwindSafe for ServiceToImport<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,