pub struct SaTokenConfigBuilder { /* private fields */ }Expand description
配置构建器
Implementations§
Source§impl SaTokenConfigBuilder
impl SaTokenConfigBuilder
pub fn token_name(self, name: impl Into<String>) -> SaTokenConfigBuilder
pub fn timeout(self, timeout: i64) -> SaTokenConfigBuilder
pub fn active_timeout(self, timeout: i64) -> SaTokenConfigBuilder
Sourcepub fn dynamic_active_timeout(self, enabled: bool) -> SaTokenConfigBuilder
pub fn dynamic_active_timeout(self, enabled: bool) -> SaTokenConfigBuilder
设置是否启用 per-token 动态 active_timeout
Sourcepub fn auto_renew(self, enabled: bool) -> SaTokenConfigBuilder
pub fn auto_renew(self, enabled: bool) -> SaTokenConfigBuilder
设置是否开启自动续签
pub fn is_concurrent(self, concurrent: bool) -> SaTokenConfigBuilder
pub fn token_style(self, style: TokenStyle) -> SaTokenConfigBuilder
Sourcepub fn storage_key_prefix(
self,
prefix: impl Into<String>,
) -> SaTokenConfigBuilder
pub fn storage_key_prefix( self, prefix: impl Into<String>, ) -> SaTokenConfigBuilder
设置存储键前缀(默认 “sa:”)
注意:此字段与 token_prefix(HTTP header 中的 Bearer 前缀)不同 此前缀用于 Redis/数据库等存储后端的键命名
pub fn jwt_secret_key(self, key: impl Into<String>) -> SaTokenConfigBuilder
Sourcepub fn jwt_algorithm(self, algorithm: impl Into<String>) -> SaTokenConfigBuilder
pub fn jwt_algorithm(self, algorithm: impl Into<String>) -> SaTokenConfigBuilder
设置 JWT 算法
Sourcepub fn jwt_issuer(self, issuer: impl Into<String>) -> SaTokenConfigBuilder
pub fn jwt_issuer(self, issuer: impl Into<String>) -> SaTokenConfigBuilder
设置 JWT 签发者
Sourcepub fn jwt_audience(self, audience: impl Into<String>) -> SaTokenConfigBuilder
pub fn jwt_audience(self, audience: impl Into<String>) -> SaTokenConfigBuilder
设置 JWT 受众
pub fn jwt_fallback_on_error(self, fallback: bool) -> SaTokenConfigBuilder
Sourcepub fn enable_nonce(self, enable: bool) -> SaTokenConfigBuilder
pub fn enable_nonce(self, enable: bool) -> SaTokenConfigBuilder
启用防重放攻击(nonce 机制)
Sourcepub fn nonce_timeout(self, timeout: i64) -> SaTokenConfigBuilder
pub fn nonce_timeout(self, timeout: i64) -> SaTokenConfigBuilder
设置 Nonce 有效期(秒)
Sourcepub fn enable_refresh_token(self, enable: bool) -> SaTokenConfigBuilder
pub fn enable_refresh_token(self, enable: bool) -> SaTokenConfigBuilder
启用 Refresh Token
Sourcepub fn refresh_token_timeout(self, timeout: i64) -> SaTokenConfigBuilder
pub fn refresh_token_timeout(self, timeout: i64) -> SaTokenConfigBuilder
设置 Refresh Token 有效期(秒)
pub fn max_login_count(self, count: i64) -> SaTokenConfigBuilder
pub fn overflow_logout_mode(self, mode: LogoutMode) -> SaTokenConfigBuilder
pub fn replaced_login_exit_mode( self, mode: ReplacedLoginExitMode, ) -> SaTokenConfigBuilder
pub fn replaced_range(self, range: ReplacedRange) -> SaTokenConfigBuilder
pub fn right_now_create_token_session( self, enabled: bool, ) -> SaTokenConfigBuilder
pub fn token_session_check_login(self, enabled: bool) -> SaTokenConfigBuilder
pub fn logout_range(self, range: LogoutRange) -> SaTokenConfigBuilder
pub fn is_logout_keep_token_session(self, keep: bool) -> SaTokenConfigBuilder
Sourcepub fn storage(self, storage: Arc<dyn SaStorage>) -> SaTokenConfigBuilder
pub fn storage(self, storage: Arc<dyn SaStorage>) -> SaTokenConfigBuilder
设置存储方式
Sourcepub fn register_listener(
self,
listener: Arc<dyn SaTokenListener>,
) -> SaTokenConfigBuilder
pub fn register_listener( self, listener: Arc<dyn SaTokenListener>, ) -> SaTokenConfigBuilder
注册事件监听器
可以多次调用以注册多个监听器
§示例
use std::sync::Arc;
use sa_token_core::{SaTokenConfig, SaTokenListener};
struct MyListener;
impl SaTokenListener for MyListener { /* ... */ }
let manager = SaTokenConfig::builder()
.storage(Arc::new(MemoryStorage::new()))
.register_listener(Arc::new(MyListener))
.build();Sourcepub fn build(self) -> SaTokenManager
pub fn build(self) -> SaTokenManager
构建 SaTokenManager(需要先设置 storage)
自动完成以下操作:
- 创建 SaTokenManager
- 注册所有事件监听器
- 初始化 StpUtil
Auto-complete the following operations:
- Create SaTokenManager
- Register all event listeners
- Initialize StpUtil
§Panics
如果未设置 storage,会 panic
§示例
use std::sync::Arc;
use sa_token_core::SaTokenConfig;
use sa_token_storage_memory::MemoryStorage;
// 一行代码完成所有初始化!
// Complete all initialization in one line!
SaTokenConfig::builder()
.storage(Arc::new(MemoryStorage::new()))
.timeout(7200)
.register_listener(Arc::new(MyListener))
.build(); // 自动初始化 StpUtil!Sourcepub fn build_config(self) -> SaTokenConfig
pub fn build_config(self) -> SaTokenConfig
仅构建配置(不创建 Manager)
Trait Implementations§
Source§impl Default for SaTokenConfigBuilder
impl Default for SaTokenConfigBuilder
Source§fn default() -> SaTokenConfigBuilder
fn default() -> SaTokenConfigBuilder
Auto Trait Implementations§
impl !RefUnwindSafe for SaTokenConfigBuilder
impl !UnwindSafe for SaTokenConfigBuilder
impl Freeze for SaTokenConfigBuilder
impl Send for SaTokenConfigBuilder
impl Sync for SaTokenConfigBuilder
impl Unpin for SaTokenConfigBuilder
impl UnsafeUnpin for SaTokenConfigBuilder
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> 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> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
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 moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);