Skip to main content

MemorySerialBackend

Struct MemorySerialBackend 

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

基于内存 + tokio::sync::Mutex 的单号生成后端

适用于单机部署。计数器按 {rule_key}:{cycle_value} 维度分组存储。

§示例

let backend = MemorySerialBackend::new();
backend.register_rule(SerialRule::new("order", "ORD{SEQ:6}")).await?;
let no = backend.generate("order").await?;

Implementations§

Source§

impl MemorySerialBackend

Source

pub fn new() -> Self

创建内存后端(最多保留 10000 条记录)

Source

pub fn with_max_records(self, max: usize) -> Self

设置最大记录数

Trait Implementations§

Source§

impl Default for MemorySerialBackend

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl SerialGenerator for MemorySerialBackend

Source§

fn generate<'life0, 'life1, 'async_trait>( &'life0 self, rule_key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String, SerialError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

生成下一个单号
Source§

fn batch_generate<'life0, 'life1, 'async_trait>( &'life0 self, rule_key: &'life1 str, count: u32, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, SerialError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

批量生成单号
Source§

fn peek<'life0, 'life1, 'async_trait>( &'life0 self, rule_key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String, SerialError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

预览下一个单号(不消耗计数器)
Source§

fn register_rule<'life0, 'async_trait>( &'life0 self, rule: SerialRule, ) -> Pin<Box<dyn Future<Output = Result<(), SerialError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

运行时注册/更新一条规则
Source§

fn remove_rule<'life0, 'life1, 'async_trait>( &'life0 self, rule_key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), SerialError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

运行时删除一条规则
Source§

fn enable_rule<'life0, 'life1, 'async_trait>( &'life0 self, rule_key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), SerialError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

运行时启用一条规则
Source§

fn disable_rule<'life0, 'life1, 'async_trait>( &'life0 self, rule_key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), SerialError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

运行时禁用一条规则
Source§

fn query_records<'life0, 'life1, 'async_trait>( &'life0 self, rule_key: &'life1 str, page: u64, page_size: u64, ) -> Pin<Box<dyn Future<Output = Result<(Vec<SerialRecord>, u64), SerialError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

查询生成记录(分页),返回 (记录列表, 总数)
Source§

fn list_rules<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<SerialRule>, SerialError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

获取所有已注册的规则

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> 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> Same for T

Source§

type Output = T

Should always be Self
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