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: AtomicBoolWhether to record error log
tokio: Option<Box<Handle>>Tokio runtime handle
Implementations§
Source§impl Session
impl Session
Sourcepub fn from<A: Adapter, S: Service>(adapter: A, service: S) -> Self
pub fn from<A: Adapter, S: Service>(adapter: A, service: S) -> Self
Simple wrapper for Session::new()
Sourcepub fn new(adapter: Arc<dyn Adapter>, service: Arc<dyn Service>) -> Self
pub fn new(adapter: Arc<dyn Adapter>, service: Arc<dyn Service>) -> Self
Create a new Session from an adapter and a service
Sourcepub fn downcast_adapter<A: Adapter>(&self) -> Option<Arc<A>>
pub fn downcast_adapter<A: Adapter>(&self) -> Option<Arc<A>>
Try downcast the adaptor trait object to its concrete type
Sourcepub fn downcast_service<S: Service>(&self) -> Option<Arc<S>>
pub fn downcast_service<S: Service>(&self) -> Option<Arc<S>>
Try downcast the service trait object to its concrete type
Sourcepub fn mapped_service<T: Send + Sync + 'static>(&self) -> Arc<MappedService<T>>
pub fn mapped_service<T: Send + Sync + 'static>(&self) -> Arc<MappedService<T>>
Assert the service is a MappedService
Source§impl Session
impl Session
Sourcepub async fn notify<A: Serialize, M: Serialize>(
&self,
method: M,
args: A,
) -> Result<()>
pub async fn notify<A: Serialize, M: Serialize>( &self, method: M, args: A, ) -> Result<()>
Do a notify RPC
Sourcepub async fn notify_de<'de, A: Deserializer<'de>, M: Deserializer<'de>>(
&self,
method: M,
args: A,
) -> Result<()>
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
pub fn notify_sync<A: Serialize, M: Serialize>( &self, method: M, args: A, ) -> Result<()>
Sourcepub async fn request<A: Serialize, M: Serialize, R: FromPacket>(
self: &Arc<Self>,
method: M,
args: A,
) -> Result<R>
pub async fn request<A: Serialize, M: Serialize, R: FromPacket>( self: &Arc<Self>, method: M, args: A, ) -> Result<R>
Do a request RPC
Sourcepub async fn request_recver<A: Serialize, M: Serialize>(
self: &Arc<Self>,
method: M,
args: A,
) -> Result<StreamReceiver>
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
Sourcepub 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>
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
pub async fn request_recver_de<'de, A: Deserializer<'de>, M: Deserializer<'de>>( self: &Arc<Self>, method: M, args: A, ) -> Result<StreamReceiver>
pub fn request_sync<A: Serialize, M: Serialize, R: FromPacket>( self: &Arc<Self>, method: M, args: A, ) -> Result<R>
Sourcepub async fn request_packet<A: Serialize, M: Serialize>(
self: &Arc<Self>,
method: M,
args: A,
) -> Result<Packet>
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
Sourcepub 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<()>
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
Sourcepub async fn loop_dispatch(self: &Arc<Self>) -> Result<()>
pub async fn loop_dispatch(self: &Arc<Self>) -> Result<()>
Repeatly do dispath until the adapter disconnect
Sourcepub async fn dispatch(self: &Arc<Self>) -> Result<()>
pub async fn dispatch(self: &Arc<Self>) -> Result<()>
Receive a packet and dispatch to service to handle it once
pub fn dispatch_sync(self: &Arc<Self>) -> Result<()>
pub fn try_recv_sync(&self) -> Option<Result<Packet>>
Sourcepub async fn transfer_packet(
self: &Arc<Self>,
from: &Self,
packet: &Packet,
) -> Result<()>
pub async fn transfer_packet( self: &Arc<Self>, from: &Self, packet: &Packet, ) -> Result<()>
Transfer a packet from other session to this session
Sourcepub async fn response(&self, req_id: u32, args: impl Serialize) -> Result<()>
pub async fn response(&self, req_id: u32, args: impl Serialize) -> Result<()>
Response a request manually
Sourcepub async fn response_de<'de, A: Deserializer<'de>>(
&self,
req_id: u32,
args: A,
) -> Result<()>
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
pub fn response_sync(&self, req_id: u32, args: impl Serialize) -> Result<()>
Sourcepub async fn response_error(
&self,
req_id: u32,
err: impl AsRef<str>,
) -> Result<()>
pub async fn response_error( &self, req_id: u32, err: impl AsRef<str>, ) -> Result<()>
Response a request with error message manually