Session

Struct Session 

Source
pub struct Session {
    pub adapter: Arc<dyn Adapter>,
    pub service: Arc<dyn Service>,
    pub log_error: AtomicBool,
    pub tokio: Option<Box<Handle>>,
    /* private fields */
}
Expand description

Represents a RPC session.

A session represents a connection endpoint of the adapter, such as a websocket, named pipe, etc.

Fields§

§adapter: Arc<dyn Adapter>

Adapter object

§service: Arc<dyn Service>

Service object

§log_error: AtomicBool

Whether to record error log

§tokio: Option<Box<Handle>>

Tokio runtime handle

Implementations§

Source§

impl Session

Source

pub fn from<A: Adapter, S: Service>(adapter: A, service: S) -> Self

Simple wrapper for Session::new()

Source

pub fn new(adapter: Arc<dyn Adapter>, service: Arc<dyn Service>) -> Self

Create a new Session from an adapter and a service

Source

pub fn downcast_adapter<A: Adapter>(&self) -> Option<Arc<A>>

Try downcast the adaptor trait object to its concrete type

Source

pub fn downcast_service<S: Service>(&self) -> Option<Arc<S>>

Try downcast the service trait object to its concrete type

Source

pub fn mapped_service<T: Send + Sync + 'static>(&self) -> Arc<MappedService<T>>

Assert the service is a MappedService

Source§

impl Session

Source

pub async fn notify<A: Serialize, M: Serialize>( &self, method: M, args: A, ) -> Result<()>

Do a notify RPC

Source

pub async fn notify_de<'de, A: Deserializer<'de>, M: Deserializer<'de>>( &self, method: M, args: A, ) -> Result<()>

Do a notify RPC, encode args from a Deserializer

Source

pub fn notify_sync<A: Serialize, M: Serialize>( &self, method: M, args: A, ) -> Result<()>

Source

pub async fn request<A: Serialize, M: Serialize, R: FromPacket>( self: &Arc<Self>, method: M, args: A, ) -> Result<R>

Do a request RPC

Source

pub async fn request_recver<A: Serialize, M: Serialize>( self: &Arc<Self>, method: M, args: A, ) -> Result<StreamReceiver>

Do a request RPC, and receive its result as a stream

Source

pub async fn request_de<'de, A: Deserializer<'de>, M: Deserializer<'de>, R: Serializer>( self: &Arc<Self>, method: M, args: A, result: R, ) -> Result<R::Ok>

Do a request RPCd, encode args from a Deserializer

Source

pub async fn request_recver_de<'de, A: Deserializer<'de>, M: Deserializer<'de>>( self: &Arc<Self>, method: M, args: A, ) -> Result<StreamReceiver>

Source

pub fn request_sync<A: Serialize, M: Serialize, R: FromPacket>( self: &Arc<Self>, method: M, args: A, ) -> Result<R>

Source

pub async fn request_packet<A: Serialize, M: Serialize>( self: &Arc<Self>, method: M, args: A, ) -> Result<Packet>

Do a request RPC, return the raw packet rather than deserializing the requested data

Source

pub async fn request_with<A: Serialize, M: Serialize, FUT: Future<Output = ()> + NeedSend, F: FnOnce(Packet) -> FUT + Send + 'static>( &self, method: M, args: A, callback: F, ) -> Result<()>

Do a request RPC with your async callback

Source

pub async fn loop_dispatch(self: &Arc<Self>) -> Result<()>

Repeatly do dispath until the adapter disconnect

Source

pub async fn dispatch(self: &Arc<Self>) -> Result<()>

Receive a packet and dispatch to service to handle it once

Source

pub fn dispatch_sync(self: &Arc<Self>) -> Result<()>

Source

pub async fn try_recv(&self) -> Option<Result<Packet>>

Try to receive a packet

Source

pub fn try_recv_sync(&self) -> Option<Result<Packet>>

Source

pub async fn transfer_packet( self: &Arc<Self>, from: &Self, packet: &Packet, ) -> Result<()>

Transfer a packet from other session to this session

Source

pub async fn response(&self, req_id: u32, args: impl Serialize) -> Result<()>

Response a request manually

Source

pub async fn response_de<'de, A: Deserializer<'de>>( &self, req_id: u32, args: A, ) -> Result<()>

Response a request manually, encode args from a Deserializer

Source

pub fn response_sync(&self, req_id: u32, args: impl Serialize) -> Result<()>

Source

pub async fn response_error( &self, req_id: u32, err: impl AsRef<str>, ) -> Result<()>

Response a request with error message manually

Source

pub async fn stream_packet( &self, req_id: u32, args: impl Serialize, ) -> Result<()>

Source

pub async fn stream_packet_end(&self, req_id: u32) -> Result<()>

Source

pub fn response_error_sync( &self, req_id: u32, err: impl AsRef<str>, ) -> Result<()>

Source§

impl Session

Source

pub fn ws_adapter(&self) -> Option<Arc<WsAdapter>>

Source

pub async fn ws_connect<A: ToString + AsRef<str>, S: Service>( address: A, service: S, ) -> Result<Self>

Source

pub async fn ws_accept<A: ToSocketAddrs, S: Service>( address: A, service: S, ) -> Result<Self>

Auto Trait Implementations§

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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more