Rust crate implementing short & stable ids based on timestamps

Overview

Lexicoid

Build Status Crates.io docs.rs

Short & stable IDs based on timestamps.

Heavily inspired by Short, friendly base32 slugs from timestamps by @brandur.

Install

Install with cargo by updating your Cargo.toml:

[dependencies]
lexicoid = "*"

or with cargo-add you can run:

cargo add lexicoid

Usage

use lexicoid::*;

// generates a lexicoid for the current timestamp
println!("{}", lexicoid_now()); // gj7x3vc

// generates a lexicoid for a given unix timestamp (as u64)
println!("{}", lexicoid(1654401676)); // gei4p52

Use cases

Whenever you need simple and short ids that are lexicographically sorted based on the generation timestamp.

Examples:

  • @brandur, who inspired this crate, uses this to generate ids for short entries on his website.
  • You want to obfuscate filenames in a folder and replace them with strings that are still preserving lexicographic sorting (based on file creation or modification time).
  • You need to prefix filenames with a unique id while keeping them sorted by creation (e.g. to manage your own blog posts, migration files or other types of files that you end up creating slowly over time).

Warning: since the resolution of the timestamps is per second, if you try to generate multiple ids in the same second, they will all be equal. This is not directly suitable for high frequency ID generation. But, if you need to adapt this approach to high frequency ID generation, you can always append the current number of milliseconds (or nanoseconds) to the generated ID.

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.

License

Licensed under MIT License. © Luciano Mammino.

You might also like...
Rust-idiomatic, compliant, flexible and performant BIP21 crate

Rust implementation of BIP21 Rust-idiomatic, compliant, flexible and performant BIP21 crate. About Important: while lot of work went into polishing th

Rust crate to implement a counterpart to the PBRT book's (3rd edition) C++ code.
Rust crate to implement a counterpart to the PBRT book's (3rd edition) C++ code.

Rust crate to implement a counterpart to the PBRT book's (3rd edition) C++ code.

Demonstration of how to use the rust object_store crate

Introduction Demonstration of how to use the Rust object_store crate Example

A tool that helps you to turn in one command a Rust crate into a Haskell Cabal library!
A tool that helps you to turn in one command a Rust crate into a Haskell Cabal library!

cabal-pack A tool that helps you to turn in one command a Rust crate into a Haskell Cabal library! To generate bindings, you need to annotate the Rust

Rust crate for obfuscating string literals.

Obfustring This crate provides a obfuscation macro for string literals. This makes it easy to protect them from common reverse engineering attacks lik

c-library wrapper around the rust pdb crate

pdbcrust: pdbcrust is a c-library wrapper around the rust pdb crate. The API only exports a minimum subset of the pdb crate functionality. The project

🦀 Rust crate that allows creating weighted prefix trees that can be used in autocomplete

weighted_trie 🦀 Rust crate that allows creating weighted prefix trees that can be used in autocomplete Released API Docs Quickstart To use weigthed-t

A Rust crate providing utility functions and macros.

介绍 此库提供四类功能:异常处理、http post收发对象、格式转换、语法糖。 在 Cargo.toml 里添加如下依赖项 [dependencies.xuanmi_base_support] git = "https://github.com/taiyi-research-institute/x

Rust crate: Overloaded Literals to construct your datatypes without boilerplate and with compile-time validation.

overloaded_literals   Overloaded Literals to construct your datatypes without boilerplate and with compile-time validation. Features Compile-time vali

Releases(0.1.0)
Owner
Luciano Mammino
FullStack ☁️ developer, entrepreneur, fighter, butterfly maker! 📗 Co-author https://nodejsdp.link 💌 maintainer https://fstack.link
Luciano Mammino
A short exercise to introduce people to the Rust programming language

Searching primes by brute force This code is ment to be an exercice to teach rust and give a first impression on how to work with the language during

JoelImgu 3 Dec 14, 2022
Tools to feature more lenient Polonius-based borrow-checker patterns in stable Rust

Though this be madness, yet there is method in 't. More context Hamlet: For yourself, sir, shall grow old as I am – if, like a crab, you could go back

Daniel Henry-Mantilla 52 Dec 26, 2022
(lifetime) GATs in stable Rust

::nougat Use (lifetime-)GATs on stable rust. Example #![forbid(unsafe_code)] #[macro_use] extern crate nougat; #[gat] trait LendingIterator { ty

Daniel Henry-Mantilla 45 Dec 26, 2022
A traditional web forum built in Rust with modern technology to be fast, secure, scalable, and stable.

Volksforo A traditional web forum built in Rust with modern technology to be fast, secure, scalable, and stable. Stack Rust actix-web askama ScyllaDB

Josh 5 Mar 21, 2023
Rust libraries for Bluesky's AT Protocol services. NOT STABLE (yet)

ATrium ATrium is a collection of Rust libraries designed to work with the AT Protocol, providing a versatile and coherent ecosystem for developers. Th

Yoshihiro Sugi 43 Jun 25, 2023
An attempt at implementing a state-of-the-art Voxel DAG in Rust

VDAG Introduction This is an attempt at implementing a state-of-the-art compressed voxel data structure, as described in a number of papers ([PDFs] Ka

SamCasavant 2 Aug 25, 2022
Macro for fast implementing serialize methods in serde::Serializer trait

impl_serialize! This library provides a simple procedural macro for fast implementing serialize methods in serde::Serializer trait. [dependencies] imp

Eduard Baturin 2 Sep 6, 2022
Rust Imaging Library: A high-level Rust imaging crate.

ril Rust Imaging Library: A performant and high-level Rust imaging crate. Documentation • Crates.io • Discord What's this? This is a Rust crate design

Jay3332 18 Jan 5, 2023
An experimental Rust crate for sigstore

Continuous integration Docs License This is an experimental crate to interact with sigstore. This is under high development, many features and checks

Flavio Castelli 0 Jan 10, 2022
Rust on ESP32 STD "Hello, World" app. A "Hello, world!" STD binary crate for the ESP32[XX] and ESP-IDF.

Rust on ESP32 STD "Hello, World" app A "Hello, world!" STD binary crate for the ESP32[XX] and ESP-IDF. This is the crate you get when running cargo ne

Ivan Markov 138 Jan 1, 2023