#[repr(transparent)]pub struct Fuid<H>(pub u64_be, _);Expand description
- 64bit id [–timestamp(40)–|–shard_id(8)–|–seq_id(16)–]
- 40 bit - timestamp (in milliseconds) started from 2023-04-09 0:00:00 UTC, 34 years available (from 2023 to 2057)
- 8 bit - shard_id ([datacenter_id / instance_id] with thread_id), 256 values
- 16 bit - random sequence id (unique for thread / per thread), 65_536 values
- Blowfish for encryption
- ZBASE32 for encoding into 13 length string (example: “ifs1gp9dw8hdw”)
- create ~ 50ns (~ 21k in 1ms or 21m in 1s) in 1 thread
Notes:
- checks timestamp and shard_id when deserialized from string
- Fuid is not inlined for InlineArray
Tuple Fields§
§0: u64_beImplementations§
Source§impl<H> Fuid<H>
impl<H> Fuid<H>
pub fn from_thread() -> Self
Sourcepub fn with_inst_thread(instance_id: u64, thread_id: u64) -> Self
pub fn with_inst_thread(instance_id: u64, thread_id: u64) -> Self
- 3 bit - instance id (datacenter id / shard id) (max 7)
- 5 bit - thread id (max 31)
- instance_id (datacenter) < 8 and thread_id (worker) < 32
Sourcepub fn with_shard(shard_id: u64) -> Self
pub fn with_shard(shard_id: u64) -> Self
Create a new Fuid.
- shard_id < 256
pub fn date(&self) -> OffsetDateTime
pub fn to_be_bytes(self) -> [u8; 8]
pub fn from_be_bytes(bytes: [u8; 8]) -> Self
Sourcepub fn from_bytes(bytes: [u8; 8]) -> Self
pub fn from_bytes(bytes: [u8; 8]) -> Self
from BE bytes
pub fn to_le_bytes(self) -> [u8; 8]
pub fn instance_id(&self) -> u64
pub fn thread_id(&self) -> u64
pub fn shard_id(&self) -> u64
Sourcepub fn format<W>(&self, w: &mut W) -> Result<(), Error>where
W: Write,
pub fn format<W>(&self, w: &mut W) -> Result<(), Error>where
W: Write,
id: {id:#x}; {id:#b}; {dt}-{instance_id}-{thread_id}-{seq}
Sourcepub fn date_prefix(ms: u64) -> [u8; 8]
pub fn date_prefix(ms: u64) -> [u8; 8]
return prefix for date [–timestamp(5)–|0x00(1)|0x0000(2)] ms - unix timestamp in milliseconds
pub fn check(&self) -> Result<(), ArmourError>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Fuid<()>
Available on crate feature std only.
impl<'de> Deserialize<'de> for Fuid<()>
Available on crate feature
std only.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
Source§impl<'de, T: IdHasher> Deserialize<'de> for Fuid<T>
Available on crate feature std only.
impl<'de, T: IdHasher> Deserialize<'de> for Fuid<T>
Available on crate feature
std only.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
Source§impl<H> FromBytes for Fuid<H>
impl<H> FromBytes for Fuid<H>
Source§fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
Source§fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
Source§fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: Immutable + KnownLayout,
fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: Immutable + KnownLayout,
Interprets the suffix of the given bytes as a
&Self. Read moreSource§fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
Source§fn mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
fn mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
Source§fn mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
fn mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
Source§impl<H> IntoBytes for Fuid<H>
impl<H> IntoBytes for Fuid<H>
Source§fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
Gets the bytes of this value mutably. Read more
Source§fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
Source§impl<H> KnownLayout for Fuid<H>where
Self: Sized,
impl<H> KnownLayout for Fuid<H>where
Self: Sized,
Source§type PointerMetadata = ()
type PointerMetadata = ()
The type of metadata stored in a pointer to
Self. Read moreSource§fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>
fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>
Computes the size of an object of type
Self with the given pointer
metadata. Read moreSource§impl<T> Ord for Fuid<T>
impl<T> Ord for Fuid<T>
Source§impl<T> PartialOrd for Fuid<T>
impl<T> PartialOrd for Fuid<T>
Source§impl Rapira for Fuid<()>
impl Rapira for Fuid<()>
const STATIC_SIZE: Option<usize>
const MIN_SIZE: usize = 8
Source§fn check_bytes(slice: &mut &[u8]) -> Result<()>
fn check_bytes(slice: &mut &[u8]) -> Result<()>
check bytes, collections len, check utf-8, NonZero, f32 and others…
Source§fn from_slice(slice: &mut &[u8]) -> Result<Self>where
Self: Sized,
fn from_slice(slice: &mut &[u8]) -> Result<Self>where
Self: Sized,
this is safe, but not check collections capacity!
recommend use only for safe data (example: from DB), not external data.
fn convert_to_bytes(&self, slice: &mut [u8], cursor: &mut usize)
fn debug_from_slice(slice: &mut &[u8]) -> Result<Self, RapiraError>
Source§unsafe fn from_slice_unchecked(slice: &mut &[u8]) -> Result<Self, RapiraError>where
Self: Sized,
unsafe fn from_slice_unchecked(slice: &mut &[u8]) -> Result<Self, RapiraError>where
Self: Sized,
Safety Read more
Source§unsafe fn from_slice_unsafe(slice: &mut &[u8]) -> Result<Self, RapiraError>where
Self: Sized,
unsafe fn from_slice_unsafe(slice: &mut &[u8]) -> Result<Self, RapiraError>where
Self: Sized,
Safety Read more
Source§fn from_slice_versioned(
slice: &mut &[u8],
_version: u8,
) -> Result<Self, RapiraError>where
Self: Sized,
fn from_slice_versioned(
slice: &mut &[u8],
_version: u8,
) -> Result<Self, RapiraError>where
Self: Sized,
Deserialize with schema version awareness. Read more
fn try_convert_to_bytes( &self, slice: &mut [u8], cursor: &mut usize, ) -> Result<(), RapiraError>
Source§fn convert_to_bytes_ctx(
&self,
slice: &mut [u8],
cursor: &mut usize,
_flags: RapiraFlags,
)
fn convert_to_bytes_ctx( &self, slice: &mut [u8], cursor: &mut usize, _flags: RapiraFlags, )
Context-aware serialization. Default: delegates to
convert_to_bytes.Source§fn from_slice_ctx(
slice: &mut &[u8],
_flags: RapiraFlags,
) -> Result<Self, RapiraError>where
Self: Sized,
fn from_slice_ctx(
slice: &mut &[u8],
_flags: RapiraFlags,
) -> Result<Self, RapiraError>where
Self: Sized,
Context-aware deserialization. Default: delegates to
from_slice.Source§fn size_ctx(&self, _flags: RapiraFlags) -> usize
fn size_ctx(&self, _flags: RapiraFlags) -> usize
Context-aware size calculation. Default: delegates to
size.Source§impl<H: IdHasher> Rapira for Fuid<H>
only check if non-zero, not check valid byte mask
impl<H: IdHasher> Rapira for Fuid<H>
only check if non-zero, not check valid byte mask
const STATIC_SIZE: Option<usize>
const MIN_SIZE: usize = 8
Source§fn check_bytes(slice: &mut &[u8]) -> Result<()>
fn check_bytes(slice: &mut &[u8]) -> Result<()>
check bytes, collections len, check utf-8, NonZero, f32 and others…
Source§fn from_slice(slice: &mut &[u8]) -> Result<Self>where
Self: Sized,
fn from_slice(slice: &mut &[u8]) -> Result<Self>where
Self: Sized,
this is safe, but not check collections capacity!
recommend use only for safe data (example: from DB), not external data.
fn convert_to_bytes(&self, slice: &mut [u8], cursor: &mut usize)
Source§fn convert_to_bytes_ctx(
&self,
slice: &mut [u8],
cursor: &mut usize,
flags: RapiraFlags,
)
fn convert_to_bytes_ctx( &self, slice: &mut [u8], cursor: &mut usize, flags: RapiraFlags, )
Context-aware serialization. Default: delegates to
convert_to_bytes.Source§fn from_slice_ctx(slice: &mut &[u8], flags: RapiraFlags) -> Result<Self>where
Self: Sized,
fn from_slice_ctx(slice: &mut &[u8], flags: RapiraFlags) -> Result<Self>where
Self: Sized,
Context-aware deserialization. Default: delegates to
from_slice.fn debug_from_slice(slice: &mut &[u8]) -> Result<Self, RapiraError>
Source§unsafe fn from_slice_unchecked(slice: &mut &[u8]) -> Result<Self, RapiraError>where
Self: Sized,
unsafe fn from_slice_unchecked(slice: &mut &[u8]) -> Result<Self, RapiraError>where
Self: Sized,
Safety Read more
Source§unsafe fn from_slice_unsafe(slice: &mut &[u8]) -> Result<Self, RapiraError>where
Self: Sized,
unsafe fn from_slice_unsafe(slice: &mut &[u8]) -> Result<Self, RapiraError>where
Self: Sized,
Safety Read more
Source§fn from_slice_versioned(
slice: &mut &[u8],
_version: u8,
) -> Result<Self, RapiraError>where
Self: Sized,
fn from_slice_versioned(
slice: &mut &[u8],
_version: u8,
) -> Result<Self, RapiraError>where
Self: Sized,
Deserialize with schema version awareness. Read more
fn try_convert_to_bytes( &self, slice: &mut [u8], cursor: &mut usize, ) -> Result<(), RapiraError>
Source§fn size_ctx(&self, _flags: RapiraFlags) -> usize
fn size_ctx(&self, _flags: RapiraFlags) -> usize
Context-aware size calculation. Default: delegates to
size.Source§impl<H> TransparentWrapper<u64_be> for Fuid<H>
impl<H> TransparentWrapper<u64_be> for Fuid<H>
Source§fn wrap_ref(s: &Inner) -> &Self
fn wrap_ref(s: &Inner) -> &Self
Convert a reference to the inner type into a reference to the wrapper
type.
Source§fn wrap_mut(s: &mut Inner) -> &mut Self
fn wrap_mut(s: &mut Inner) -> &mut Self
Convert a mutable reference to the inner type into a mutable reference to
the wrapper type.
Source§fn wrap_slice(s: &[Inner]) -> &[Self]where
Self: Sized,
fn wrap_slice(s: &[Inner]) -> &[Self]where
Self: Sized,
Convert a slice to the inner type into a slice to the wrapper type.
Source§fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]where
Self: Sized,
fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]where
Self: Sized,
Convert a mutable slice to the inner type into a mutable slice to the
wrapper type.
Source§fn peel_ref(s: &Self) -> &Inner
fn peel_ref(s: &Self) -> &Inner
Convert a reference to the wrapper type into a reference to the inner
type.
Source§fn peel_mut(s: &mut Self) -> &mut Inner
fn peel_mut(s: &mut Self) -> &mut Inner
Convert a mutable reference to the wrapper type into a mutable reference
to the inner type.
Source§fn peel_slice(s: &[Self]) -> &[Inner]where
Self: Sized,
fn peel_slice(s: &[Self]) -> &[Inner]where
Self: Sized,
Convert a slice to the wrapped type into a slice to the inner type.
Source§fn peel_slice_mut(s: &mut [Self]) -> &mut [Inner]where
Self: Sized,
fn peel_slice_mut(s: &mut [Self]) -> &mut [Inner]where
Self: Sized,
Convert a mutable slice to the wrapped type into a mutable slice to the
inner type.
Source§impl TryFrom<&str> for Fuid<()>
impl TryFrom<&str> for Fuid<()>
Source§type Error = ArmourError
type Error = ArmourError
The type returned in the event of a conversion error.
Source§impl<T: IdHasher> TryFrom<&str> for Fuid<T>
impl<T: IdHasher> TryFrom<&str> for Fuid<T>
Source§type Error = ArmourError
type Error = ArmourError
The type returned in the event of a conversion error.
Source§impl<H> TryFromBytes for Fuid<H>
impl<H> TryFromBytes for Fuid<H>
Source§fn try_ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
Source§fn try_ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
Source§fn try_ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
Source§fn try_mut_from_bytes(
bytes: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout + IntoBytes,
fn try_mut_from_bytes(
bytes: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout + IntoBytes,
Source§fn try_mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout + IntoBytes,
fn try_mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout + IntoBytes,
Source§fn try_mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout + IntoBytes,
fn try_mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout + IntoBytes,
Source§fn try_read_from_bytes(
source: &[u8],
) -> Result<Self, ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_bytes(
source: &[u8],
) -> Result<Self, ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
Source§fn try_read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
Source§fn try_read_from_suffix(
source: &[u8],
) -> Result<(&[u8], Self), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_suffix(
source: &[u8],
) -> Result<(&[u8], Self), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
impl<T> Copy for Fuid<T>
impl<T> Eq for Fuid<T>
impl<H> Immutable for Fuid<H>
impl<T: 'static> Pod for Fuid<T>
Auto Trait Implementations§
impl<H> Freeze for Fuid<H>
impl<H> RefUnwindSafe for Fuid<H>where
H: RefUnwindSafe,
impl<H> Send for Fuid<H>where
H: Send,
impl<H> Sync for Fuid<H>where
H: Sync,
impl<H> Unpin for Fuid<H>where
H: Unpin,
impl<H> UnsafeUnpin for Fuid<H>
impl<H> UnwindSafe for Fuid<H>where
H: UnwindSafe,
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
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
If this function returns true, then it must be valid to reinterpret
bits
as &Self.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<I, T> TransparentWrapperAlloc<I> for T
impl<I, T> TransparentWrapperAlloc<I> for T
Source§fn wrap_vec(s: Vec<Inner>) -> Vec<Self>where
Self: Sized,
fn wrap_vec(s: Vec<Inner>) -> Vec<Self>where
Self: Sized,
Convert a vec of the inner type into a vec of the wrapper type.
Source§fn wrap_box(s: Box<Inner>) -> Box<Self>
fn wrap_box(s: Box<Inner>) -> Box<Self>
Convert a box to the inner type into a box to the wrapper
type.
Source§fn wrap_rc(s: Rc<Inner>) -> Rc<Self>
fn wrap_rc(s: Rc<Inner>) -> Rc<Self>
Convert an
Rc to the inner type into an Rc to the wrapper type.Source§fn wrap_arc(s: Arc<Inner>) -> Arc<Self>
fn wrap_arc(s: Arc<Inner>) -> Arc<Self>
Convert an
Arc to the inner type into an Arc to the wrapper type.Source§fn peel_vec(s: Vec<Self>) -> Vec<Inner>where
Self: Sized,
fn peel_vec(s: Vec<Self>) -> Vec<Inner>where
Self: Sized,
Convert a vec of the wrapper type into a vec of the inner type.
Source§fn peel_box(s: Box<Self>) -> Box<Inner>
fn peel_box(s: Box<Self>) -> Box<Inner>
Convert a box to the wrapper type into a box to the inner
type.