RpcServer

Struct RpcServer 

Source
pub struct RpcServer<Context, T: Transport + ?Sized> { /* private fields */ }
Expand description

RpcServer receives and process different requests from the RpcClient

Once a RpcServer is inited, you should attach a transport and handler for the port creation.

Implementations§

Source§

impl<Context: Send + Sync + 'static, T: Transport + ?Sized + 'static> RpcServer<Context, T>

Source

pub fn create(ctx: Context) -> Self

Source

pub fn get_server_events_sender(&self) -> ServerEventsSender<T>

Get a ServerEventsSender to send allowed server events from outside

Source

pub async fn attach_transport(&mut self, transport: Arc<T>) -> ServerResult<()>

Attaches the server half of the transport for Client<>Server communications

It differs from sending the ServerEvents::AtacchTransport because it can only be used to attach transport from the current thread where the RpcServer was initalized due to the mutably borrow

It receives the Transport inside an Arc because it must be sharable.

Source

pub async fn run(&mut self)

Start processing ServerEvent events and listening on a channel for new TransportNotification that are sent by all the attached transports that are running in background tasks.

Source

pub fn set_module_registrator_handler<H>(&mut self, handler: H)
where H: Fn(&mut RpcServerPort<Context>) + Send + Sync + 'static,

Set a handler for the port creation

When a port is created, a service should be registered for the port.

Source

pub fn set_on_transport_closes_handler<H>(&mut self, handler: H)
where H: Fn(Arc<T>, u32) + Send + Sync + 'static,

Set a handler to be executed when a transport was closed

When a transport closes its connection, the closure will be executed.

This could be useful when there are resources that may be tied to or depends on a transport’s connection

Source

pub fn set_on_transport_connected_handler<H>(&mut self, handler: H)
where H: Fn(Arc<T>, u32) + Send + Sync + 'static,

Set a handler is executed when a transport is put to run.

It works for executing a function which receives the Transport ID assigned by the server to a new running transport

Auto Trait Implementations§

§

impl<Context, T> Freeze for RpcServer<Context, T>
where T: ?Sized,

§

impl<Context, T> !RefUnwindSafe for RpcServer<Context, T>

§

impl<Context, T> Send for RpcServer<Context, T>
where Context: Sync + Send, T: ?Sized,

§

impl<Context, T> Sync for RpcServer<Context, T>
where Context: Sync + Send, T: ?Sized,

§

impl<Context, T> Unpin for RpcServer<Context, T>
where T: ?Sized,

§

impl<Context, T> !UnwindSafe for RpcServer<Context, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.