Skip to main content

Session

Struct Session 

Source
pub struct Session<I = ()> { /* private fields */ }
Expand description

Session state shared between the read loop and every dispatch task (SRV-010): the auth flag is a lock-free atomic flipped by HELLO/AUTH and read by the dispatch path without locks.

Implementations§

Source§

impl<I> Session<I>

Source

pub fn connection_id(&self) -> u64

Listener-scoped connection id, surfaced in the metadata-shape HELLO reply (SRV-014).

Source

pub fn is_authenticated(&self) -> bool

Lock-free read of the auth flag (SRV-010).

Source

pub fn with_principal<R>( &self, read: impl FnOnce(Option<&Principal<I>>) -> R, ) -> R

Read the resolved principal without cloning it — the authorization path (SRV-012).

Authorization runs on every privileged command, so it must not pay a String clone (or a credential-store lookup) to ask one question:

let is_admin = session.with_principal(|p| {
    p.map(|p| p.identity.is_admin).unwrap_or(false)
});
Source

pub fn principal_name(&self) -> Option<String>

The principal’s name, if one was resolved.

Convenience for the common case; prefer with_principal on a hot authorization path, since this clones the name.

Source

pub fn push_sender(&self) -> Option<&PushSender>

Typed push channel for this connection (SRV-013). Some only under push = Enabled profiles; under Reserved no push emission is possible.

Source§

impl<I: Clone> Session<I>

Source

pub fn principal(&self) -> Option<Principal<I>>

A clone of the principal resolved by the last successful HELLO/AUTH.

Available when the identity is Clone; on an authorization hot path prefer with_principal, which clones nothing.

Trait Implementations§

Source§

impl<I: Debug> Debug for Session<I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<I = ()> !Freeze for Session<I>

§

impl<I> RefUnwindSafe for Session<I>

§

impl<I> Send for Session<I>
where I: Send,

§

impl<I> Sync for Session<I>
where I: Send,

§

impl<I> Unpin for Session<I>
where I: Unpin,

§

impl<I> UnsafeUnpin for Session<I>
where I: UnsafeUnpin,

§

impl<I> UnwindSafe for Session<I>

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, 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.