Skip to main content

SaTokenContext

Struct SaTokenContext 

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

请求上下文句柄:Clone 共享同一 Inner,突变对所有克隆可见

Request context handle: Clone shares the same Inner; mutations are visible to all clones.

字段私有(inner: Arc<RwLock<...>>):强制走 builder / accessor API。 Fields private: forces use of builder/accessor API.

Implementations§

Source§

impl SaTokenContext

Source

pub fn new() -> Self

创建空上下文 | Create an empty context

Source

pub fn builder() -> SaTokenContextBuilder

链式 builder 入口(替代旧版 struct literal 字段赋值)

Fluent builder entry (replaces old struct literal field assignment).

Source

pub fn token(&self) -> Option<TokenValue>

读取 token(快照)| Read token (snapshot)

Source

pub fn token_info(&self) -> Option<Arc<TokenInfo>>

读取 token_info(快照)| Read token_info (snapshot)

Source

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

读取 login_id(快照)| Read login_id (snapshot)

Source

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

读取 switch_login_id(快照)| Read switch_login_id (snapshot)

Source

pub fn auth_meta(&self) -> RequestAuthMeta

Snapshot of captured auth headers. 已捕获鉴权头的快照。

Source

pub async fn scope<F, R>(ctx: SaTokenContext, fut: F) -> R
where F: Future<Output = R>,

在 fut 全生命周期内绑定本上下文(跨 await / 跨 worker 仍有效), 同时建立一份请求级授权快照(B2 特性)。

Binds this context for the whole lifetime of fut (survives across awaits/workers), and simultaneously establishes a request-scoped authorization snapshot (B2 feature).

Source

pub fn try_current() -> Option<SaTokenContext>

当前上下文副本:task-local 优先,再回落 thread-local

Current context clone: task-local first, then fallback to thread-local.

Source

pub fn get_current() -> Option<SaTokenContext>

获取当前上下文(try_current 别名)

Get current context (try_current alias).

Source

pub fn set_current(ctx: SaTokenContext)

设置当前上下文(thread-local 兜底路径,同时建立授权快照)

Set current context (thread-local fallback path; also establishes authz snapshot).

scope 内调用时会合并字段到现有句柄(不替换 Arc); scope 外直接替换 thread-local 存储。

Inside scope: merges fields into existing handle (does not replace Arc). Outside scope: replaces thread-local storage.

Source

pub fn clear()

清除当前上下文与授权快照(thread-local 兜底;task-local 随 scope 结束自动 drop)

Clear current context and authz snapshot (thread-local fallback; task-local auto-drops when scope ends).

Source

pub fn with_current_mut<F, R>(f: F) -> Option<R>
where F: FnOnce(&mut SaTokenContextInner) -> R,

单轨突变入口:优先修改 task-local 共享 Inner,否则修改 thread-local(修复 B3-1/2)

Single-track mutation entry: mutates task-local shared Inner first, else thread-local (fixes B3-1/2).

死锁警告:禁止在闭包 f 内调用 try_current() 等读上下文方法!

Deadlock warning: DO NOT call try_current() or other context-reading methods inside f!

Source

pub fn current_grant_scope() -> Option<GrantScope>

当前请求的授权快照;优先 task-local,再回落 thread-local(B2 特性)

The current request’s authorization snapshot; task-local first with a thread-local fallback (B2 feature).

Source

pub fn current_login_type() -> Option<String>

当前请求的账号体系(login_type);无上下文或字段为空时返回 None

The current request’s login type; None when absent or empty.

Trait Implementations§

Source§

impl Clone for SaTokenContext

Source§

fn clone(&self) -> SaTokenContext

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
Source§

impl Debug for SaTokenContext

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SaTokenContext

Source§

fn default() -> Self

Returns the “default value” for a type. 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> ForyObject for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = 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