pub struct SerialRule {
pub key: String,
pub format: String,
pub cycle: CyclePeriod,
pub initial_value: u64,
pub step: IncrementStrategy,
pub is_enabled: bool,
}Expand description
业务单号规则定义
一条规则 = 格式模板 + 循环周期 + 计数策略 + 启用状态。
可通过静态配置(config.toml)或运行时 API(register_rule)注册。
禁用后的规则调用 generate() 将返回 SerialError::RuleDisabled。
Fields§
§key: String规则唯一标识,如 “order”、“contract”、“purchase”
format: String单号格式,如 “ORD{YYYY}{MM}{DD}{SEQ:8}”
cycle: CyclePeriod循环周期
initial_value: u64计数器初始值(每次周期重置后从此值开始)
step: IncrementStrategy增量策略
is_enabled: bool是否启用(默认 true)。禁用后 generate() 返回错误。
Implementations§
Source§impl SerialRule
impl SerialRule
Sourcepub fn with_cycle(self, cycle: CyclePeriod) -> Self
pub fn with_cycle(self, cycle: CyclePeriod) -> Self
设置循环周期
Sourcepub fn with_initial_value(self, val: u64) -> Self
pub fn with_initial_value(self, val: u64) -> Self
设置初始值
Sourcepub fn with_step(self, step: IncrementStrategy) -> Self
pub fn with_step(self, step: IncrementStrategy) -> Self
设置增量策略
Trait Implementations§
Source§impl Clone for SerialRule
impl Clone for SerialRule
Source§fn clone(&self) -> SerialRule
fn clone(&self) -> SerialRule
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SerialRule
impl Debug for SerialRule
Source§impl<'de> Deserialize<'de> for SerialRule
impl<'de> Deserialize<'de> for SerialRule
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SerialRule
impl RefUnwindSafe for SerialRule
impl Send for SerialRule
impl Sync for SerialRule
impl Unpin for SerialRule
impl UnsafeUnpin for SerialRule
impl UnwindSafe for SerialRule
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
Mutably borrows from an owned value. Read more