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
impl SaTokenContext
Sourcepub fn new() -> SaTokenContext
pub fn new() -> SaTokenContext
创建空上下文 | Create an empty context
Sourcepub fn builder() -> SaTokenContextBuilder
pub fn builder() -> SaTokenContextBuilder
链式 builder 入口(替代旧版 struct literal 字段赋值)
Fluent builder entry (replaces old struct literal field assignment).
Sourcepub fn token(&self) -> Option<TokenValue>
pub fn token(&self) -> Option<TokenValue>
读取 token(快照)| Read token (snapshot)
Sourcepub fn token_info(&self) -> Option<Arc<TokenInfo>>
pub fn token_info(&self) -> Option<Arc<TokenInfo>>
读取 token_info(快照)| Read token_info (snapshot)
Sourcepub fn switch_login_id(&self) -> Option<String>
pub fn switch_login_id(&self) -> Option<String>
读取 switch_login_id(快照)| Read switch_login_id (snapshot)
Sourcepub fn auth_meta(&self) -> RequestAuthMeta
pub fn auth_meta(&self) -> RequestAuthMeta
Snapshot of captured auth headers. 已捕获鉴权头的快照。
Sourcepub async fn scope<F, R>(ctx: SaTokenContext, fut: F) -> Rwhere
F: Future<Output = R>,
pub async fn scope<F, R>(ctx: SaTokenContext, fut: F) -> Rwhere
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).
Sourcepub fn try_current() -> Option<SaTokenContext>
pub fn try_current() -> Option<SaTokenContext>
当前上下文副本:task-local 优先,再回落 thread-local
Current context clone: task-local first, then fallback to thread-local.
Sourcepub fn get_current() -> Option<SaTokenContext>
pub fn get_current() -> Option<SaTokenContext>
获取当前上下文(try_current 别名)
Get current context (try_current alias).
Sourcepub fn set_current(ctx: SaTokenContext)
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.
Sourcepub fn clear()
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).
Sourcepub fn with_current_mut<F, R>(f: F) -> Option<R>where
F: FnOnce(&mut SaTokenContextInner) -> R,
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!
Sourcepub fn current_grant_scope() -> Option<GrantScope>
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).
Sourcepub fn current_login_type() -> Option<String>
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
impl Clone for SaTokenContext
Source§fn clone(&self) -> SaTokenContext
fn clone(&self) -> SaTokenContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SaTokenContext
impl Debug for SaTokenContext
Source§impl Default for SaTokenContext
impl Default for SaTokenContext
Source§fn default() -> SaTokenContext
fn default() -> SaTokenContext
Auto Trait Implementations§
impl Freeze for SaTokenContext
impl RefUnwindSafe for SaTokenContext
impl Send for SaTokenContext
impl Sync for SaTokenContext
impl Unpin for SaTokenContext
impl UnsafeUnpin for SaTokenContext
impl UnwindSafe for SaTokenContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more