IdUtil

Struct IdUtil 

Source
pub struct IdUtil;
Expand description

ID工具,用于生成ID使用,UUID和雪花算法

Implementations§

Source§

impl IdUtil

Source

pub fn gen_uuid() -> String

生成UUID

Source

pub fn uuid32() -> String

生成UUID,不带中横线,共计32位

Source

pub fn uuid36() -> String

生成UUID,带中横线,共计36位

Source

pub fn random_string_id(length: usize) -> String

生成指定长度的随机字符串ID

该函数使用字母和数字字符集生成随机字符串,适用于生成唯一标识符

§参数
  • length - 指定生成字符串的长度
§返回值

返回一个包含随机字符的String,长度为指定的length

§示例
let id = random_string_id(128);
assert_eq!(id.len(), 128);
Source

pub fn tik_id() -> String

生成一个唯一的 tik ID 字符串

该函数通过组合三个随机字符串来创建一个格式化的唯一标识符。 生成的格式为: “{2位随机字符串}{14位随机字符串}{16位随机字符串}__”

§返回值
  • String - 返回生成的唯一 tik ID 字符串
§示例
let id = tik_id();
// 示例输出: "ab_cdefghijklmn_opqrstuvwxyzabcdefg__"
Source

pub fn snowflake_id() -> u64

使用雪花算法生成ID

1位0 + 41位时间戳 + 10位机器ID(5位数据中心ID + 5位机器ID) + 12位序列号 = 64位二进制数字

Auto Trait Implementations§

§

impl Freeze for IdUtil

§

impl RefUnwindSafe for IdUtil

§

impl Send for IdUtil

§

impl Sync for IdUtil

§

impl Unpin for IdUtil

§

impl UnwindSafe for IdUtil

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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, 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,