Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

异步连接、Session、请求与订阅。 只管理本地 flattened 路由的廉价 Clone 句柄;Drop 不自动 detach。

Implementations§

Source§

impl Session

Source

pub fn key(&self) -> SessionKey

返回连接与本地不可重用会话序号。

fn inspect(s: &ydp_core::Session) { let _ = s.key(); }
Source

pub fn id(&self) -> Option<&SessionId>

借用 child wire ID;根返回 None。

fn inspect(s: &ydp_core::Session) { let _ = s.id(); }
Source

pub fn is_closed(&self) -> bool

查看本地 gate;不证明远端资源已经释放。

fn inspect(s: &ydp_core::Session) { let _ = s.is_closed(); }
Source

pub fn close(&self)

同步终结 child 的本地请求和订阅,不发 detach;根发起连接退出。 已发布帧仍可能发出;必须由上层管理远端语义责任。

fn close(s: &ydp_core::Session) { s.close(); assert!(s.is_closed()); }
Source

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); }
Source

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()); }
Source

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(()) }
Source

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(()) }
Source

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§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.