Crates.io | euui |
lib.rs | euui |
version | |
source | src |
created_at | 2024-07-20 11:28:00.674692+00 |
updated_at | 2025-02-26 21:20:40.289072+00 |
description | An Extended Universal Unique Identifier |
homepage | |
repository | https://github.com/Trehinos/euui |
max_upload_size | |
id | 1309386 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Euui
is a Rust library (no_std
compatible) that provides a 512-bit (64 bytes) unique identifier, which is 4 times
larger than traditional UUIDs or GUIDs. This allows for enhanced uniqueness and adaptability in scenarios where more
significant identifiers are required.
The Euui
type can be utilized for various applications, offering readable formats and flexible access to its
components (u128
, u64
, u8
), making it a powerful alternative for unique identification in embedded or
resource-constrained environments.
Size: A single Euui
consists of 512 bits (64 bytes), making it exceptionally unique.
Formatting:
-
) and line breaks (\n
).Components Access:
u128
, 8×u64
, or 64×u8
.Generation:
Euui
using default()
.Euui
using random()
.Add the following dependency to your Cargo.toml
:
[dependencies]
euui = "1.1.0"
rand = "0.9.0"
Here are examples of how to use the Euui
library:
use euui::Euui;
fn test() {
// Generate a zero-initialized Euui
let zero_euui = Euui::default();
println!("Zero Euui: {}", zero_euui);
// Generate a random Euui
let random_euui = Euui::random();
println!("Random Euui: {}", random_euui);
// Format the Euui into a readable structure
println!("Formatted Euui:\n{}", random_euui.format());
}
You can retrieve specific components (u128
, u64
, or u8
) of the Euui
as needed:
// Access one of the u128 components
fn test() {
if let Some(first_u128) = random_euui.u128(0) {
println!("First u128: {:032x}", first_u128);
}
// Access one of the u64 components
if let Some(second_u64) = random_euui.u64(1) {
println!("Second u64: {:016x}", second_u64);
}
// Access one of the u8 components
if let Some(last_u8) = random_euui.u8(63) {
println!("Last u8: {:02x}", last_u8);
}
}
You can initialize an Euui
using custom GUIDs or bytes:
u128
array)pub fn test() {
let guids = [
0x1234567890abcdef1234567890abcdef,
0xabcdef1234567890abcdef1234567890,
0x7890abcdef1234567890abcdef123456,
0x567890abcdef1234567890abcdef1234,
];
let euui = Euui::from_be_guids(guids);
}
u8
array)pub fn test() {
let bytes = [0x12, 0x34, /* 61 other bytes... */ 0xef];
let euui = Euui::from_be_bytes(bytes);
}
The main functionalities of the Euui
type are:
Euui::default()
Creates a zero-initialized Euui
.Euui::random()
Generates a random Euui
.Euui::from_be_guids([u128; 4])
Initializes an Euui
from an array of 4×u128
.Euui::from_be_bytes([u8; 64])
Initializes an Euui
from a 64-byte array.Euui::random_from_first(u128)
Generates a new random Euui with the first u128
component provided.Euui::random_from_second(u128)
Generates a new random Euui with the second u128
component provided.Euui::random_from_third(u128)
Generates a new random Euui with the third u128
component provided.Euui::random_from_fourth(u128)
Generates a new random Euui with the fourth u128
component provided.Euui::regenerate_first(&self)
Generates a new Euui
with a randomly generated first component.Euui::regenerate_second(&self)
Generates a new Euui
with a randomly generated second component.Euui::regenerate_third(&self)
Generates a new Euui
with a randomly generated third component.Euui::regenerate_fourth(&self)
Generates a new Euui
with a randomly generated fourth component.u128(index: usize) -> Option<u128>
Retrieve a specific u128
component. Index must be in the range [0, 3]
.u64(index: usize) -> Option<u64>
Retrieve a specific u64
component. Index must be in the range [0, 7]
.u8(index: usize) -> Option<u8>
Retrieve a specific u8
component. Index must be in the range [0, 63]
.to_be_bytes() -> [u8; 64]
Retrieve the entire Euui
as an array of 64 bytes.to_be_guids() -> [u128; 4]
Retrieve the entire Euui
as an array of 4×u128
.to_string()
Converts the Euui
to a single hexadecimal string representation.format() -> String
Formats the Euui
into a structured string, following the pattern:
#1-#2
#3-#4.With 512 bits of entropy, Euui
can be useful for applications where traditional 128-bit UUIDs are insufficient to
guarantee uniqueness:
© 2024-2025 Sébastien GELDREICH
This project is licensed under the MIT License. See LICENSE for more details.