pub struct Session { /* private fields */ }Expand description
异步连接、Session、请求与订阅。 只管理本地 flattened 路由的廉价 Clone 句柄;Drop 不自动 detach。
Implementations§
Source§impl Session
impl Session
Sourcepub fn key(&self) -> SessionKey
pub fn key(&self) -> SessionKey
返回连接与本地不可重用会话序号。
fn inspect(s: &ydp_core::Session) { let _ = s.key(); }Sourcepub fn id(&self) -> Option<&SessionId>
pub fn id(&self) -> Option<&SessionId>
借用 child wire ID;根返回 None。
fn inspect(s: &ydp_core::Session) { let _ = s.id(); }Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
查看本地 gate;不证明远端资源已经释放。
fn inspect(s: &ydp_core::Session) { let _ = s.is_closed(); }Sourcepub fn close(&self)
pub fn close(&self)
同步终结 child 的本地请求和订阅,不发 detach;根发起连接退出。 已发布帧仍可能发出;必须由上层管理远端语义责任。
fn close(s: &ydp_core::Session) { s.close(); assert!(s.is_closed()); }Sourcepub fn send<C: Command>(&self, params: C::Params) -> Request<C> ⓘ
pub fn send<C: Command>(&self, params: C::Params) -> Request<C> ⓘ
创建拥有参数的冷请求;首次 poll 前没有编码、ID 或网络副作用。
fn send<C: ydp_core::Command>(s: &ydp_core::Session, params: C::Params) { let _request = s.send::<C>(params); }Sourcepub fn send_with<C: Command>(
&self,
params: C::Params,
options: RequestOptions,
) -> Request<C> ⓘ
pub fn send_with<C: Command>( &self, params: C::Params, options: RequestOptions, ) -> Request<C> ⓘ
使用指定期限和独立流量类别创建同一种冷请求;不重试。
fn send<C: ydp_core::Command>(s: &ydp_core::Session, params: C::Params) { let _request = s.send_with::<C>(params, Default::default()); }Sourcepub fn send_raw(
&self,
method: MethodName,
params: RawJson,
options: RequestOptions,
) -> RawRequest ⓘ
pub fn send_raw( &self, method: MethodName, params: RawJson, options: RequestOptions, ) -> RawRequest ⓘ
创建动态方法请求;参数在首次 poll 校验为 JSON object。
fn send(s: &ydp_core::Session) -> ydp_core::Result<()> { let params=ydp_core::RawJson::from_bytes(bytes::Bytes::from_static(b"{}"))?; let _request=s.send_raw(ydp_core::MethodName::new("Echo.echo".into())?,params,Default::default()); Ok(()) }Sourcepub fn events<E: Event>(
&self,
options: SubscriptionOptions,
) -> Result<EventStream<E>>
pub fn events<E: Event>( &self, options: SubscriptionOptions, ) -> Result<EventStream<E>>
同步安装精确 Session 与 METHOD 订阅;消费时才解码,不自动 enable。
fn subscribe<E: ydp_core::Event>(s: &ydp_core::Session) -> ydp_core::Result<()> { let _events=s.events::<E>(Default::default())?; Ok(()) }Sourcepub fn raw_events(&self, options: SubscriptionOptions) -> Result<RawEventStream>
pub fn raw_events(&self, options: SubscriptionOptions) -> Result<RawEventStream>
同步安装精确本地 Session 的所有方法订阅。
fn subscribe(s: &ydp_core::Session) -> ydp_core::Result<()> { let _events=s.raw_events(Default::default())?; Ok(()) }Trait Implementations§
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
impl UnwindSafe for Session
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more