Skip to content

Instantly share code, notes, and snippets.

@akashsoni01
Created January 10, 2024 07:16
Show Gist options
  • Save akashsoni01/5a43c1b8893166096f993bb90232d2fa to your computer and use it in GitHub Desktop.
Save akashsoni01/5a43c1b8893166096f993bb90232d2fa to your computer and use it in GitHub Desktop.
UUID vs ULID in Rust
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "d672db2a",
"metadata": {},
"outputs": [],
"source": [
":dep uuid = \"1.6.1\"\n",
":dep ulid = \"1.1.0\""
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "9d12ced4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"string = 01HKS2T7B779NTCB113A6D4MYB ulid = 01HKS2T7B779NTCB113A6D4MYB\n"
]
}
],
"source": [
"use ulid::Ulid;\n",
"\n",
"// Generate a ulid\n",
"let ulid = Ulid::new();\n",
"\n",
"// Generate a string for a ulid\n",
"let s = ulid.to_string();\n",
"\n",
"// Create from a String\n",
"let res = Ulid::from_string(&s);\n",
"\n",
"println!(\"string = {:} ulid = {:}\", s, ulid);\n",
"\n",
"assert_eq!(ulid, res.unwrap());\n"
]
},
{
"cell_type": "markdown",
"id": "9d1c81fc",
"metadata": {},
"source": [
"### uuid example "
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "924dae17",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ulid = 67e55044-10b1-426f-9247-bb680e5fe0c8\n"
]
}
],
"source": [
"use uuid::{uuid, Uuid};\n",
"\n",
"const ID: Uuid = uuid!(\"67e55044-10b1-426f-9247-bb680e5fe0c8\");\n",
"\n",
"println!(\"uuid = {:}\", ID);\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "024ff819",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Rust",
"language": "rust",
"name": "rust"
},
"language_info": {
"codemirror_mode": "rust",
"file_extension": ".rs",
"mimetype": "text/rust",
"name": "Rust",
"pygment_lexer": "rust",
"version": ""
}
},
"nbformat": 4,
"nbformat_minor": 5
}
@akashsoni01
Copy link
Author

uuid vs ulid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment