Struct ServiceToExport

Source
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

  1. Returning it while handling a method in another service
  2. 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>

Source

pub fn new(service: impl IntoSkeleton<T>) -> Self

Creates a new instance from a smart pointer of a service object.

Trait Implementations§

Source§

impl<T: ?Sized + Service> Serialize for ServiceToExport<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for ServiceToExport<T>

§

impl<T> !RefUnwindSafe for ServiceToExport<T>

§

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

§

impl<T> !Sync for ServiceToExport<T>

§

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

§

impl<T> !UnwindSafe for ServiceToExport<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.