Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Type-safe, K-sortable, globally unique identifier inspired by Stripe IDs implemented in Zig.

License

NotificationsYou must be signed in to change notification settings

nikoksr/typeid-zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

 

Type-safe, K-sortable, globally unique identifier inspired by Stripe IDs implemented in Zig.

 

ZigCI

 

About

Implementation of Type-IDs in Zig. Implemented as described by the official specification:

This implementation is part of theofficial list of community provided TypeID implementations.

What are Type-IDs?

As per the official specification:

TypeIDs are a modern, type-safe extension of UUIDv7. Inspired by a similar use of prefixesin Stripe's APIs.

TypeIDs are canonically encoded as lowercase strings consisting of three parts:

  1. A type prefix (at most 63 characters in all lowercase snake_case ASCII [a-z_]).
  2. An underscore '_' separator
  3. A 128-bit UUIDv7 encoded as a 26-character string using a modified base32 encoding.

Here's an example of a TypeID of typeuser:

user_2x4y6z8a0b1c2d3e4f5g6h7j8k  │    │  │    └── 26-character base32-encoded UUIDv7  │  └── Type prefix (snake_case [a-z_])        Max length: 63 characters

Aformal specification defines the encoding in more detail.

Installation

  1. Add as a dependency in yourbuild.zig.zon:
zig fetch --save git+https://github.com/nikoksr/typeid-zig#main
  1. In yourbuild.zig, add thetypeid module as a dependency:
consttypeid=b.dependency("typeid", .{    .target=target,    .optimize=optimize,});exe.root_module.addImport("typeid",typeid.module("typeid"));

Usage

consttypeid=@import("typeid");constTypeID=typeid.TypeID;constStringBuf=typeid.StringBuf;// Create a new TypeID with prefixconsttid=tryTypeID.init("user");// Get string representation.// StringBuf is simply a convenience buffer that's big enough to hold a TypeID of any size.//     => pub const StringBuf = [90]u8;varstr_buf:StringBuf=undefined;conststr=tid.toString(&str_buf);// "user_01h455vb4pex5vsknk084sn02q"// Parse existing TypeID stringconstparsed=tryTypeID.fromString("post_01h455vb4pex5vsknk084sn02q");

Tests

zig buildtest

About

Type-safe, K-sortable, globally unique identifier inspired by Stripe IDs implemented in Zig.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp