pub struct ServiceToExport<T: ?Sized + Service> { /* private fields */ }
Expand description
A special wrapper of skeleton, used to export a service object.
You can make any smart pointer of a trait object into a ServiceToExport
as far as the trait is a subtrait of Service
and marked with the macro service
.
The only way to actually export a ServiceToExport
is either
- Returning it while handling a method in another service
- Passing as an argument in a remote call
ServiceToExport
is a compatible type with ServiceToImport
and ServiceRef
You can import a proxy object by putting one of those two types on the same place in the client side.
See Service Compatibility section
ServiceToExport
is a wrapper of Skeleton
that hides the detail exchange process.
However you don’t have to know what Skeleton
is, unless you’re going to perform raw export and import.
NOTE: it implements Serialize
, but you must NEVER try to serialize it.
It has a side effect of registering the service object 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_proxy)]
pub trait Hello: Service {
fn hello(&self) -> Vec<ServiceToExport<dyn Hello>>;
}
struct A;
impl Service for A {}
impl Hello for A {
fn hello(&self) -> Vec<ServiceToExport<dyn Hello>> {
// Export by return
vec![
ServiceToExport::new(Box::new(A) as Box<dyn Hello>),
ServiceToExport::new(Arc::new(A) as Arc<dyn Hello>),
ServiceToExport::new(Arc::new(RwLock::new(A)) as Arc<RwLock<dyn Hello>>),
]
}
}
Implementations§
Source§impl<T: ?Sized + Service> ServiceToExport<T>
impl<T: ?Sized + Service> ServiceToExport<T>
Sourcepub fn new(service: impl IntoSkeleton<T>) -> Self
pub fn new(service: impl IntoSkeleton<T>) -> Self
Creates a new instance from a smart pointer of a service object.