{"id":18335692,"url":"https://github.com/svix/rust-ksuid","last_synced_at":"2025-04-04T23:08:50.626Z","repository":{"id":40243495,"uuid":"453431036","full_name":"svix/rust-ksuid","owner":"svix","description":"A pure-Rust KSUID implementation ","archived":false,"fork":false,"pushed_at":"2024-02-29T13:47:21.000Z","size":94,"stargazers_count":96,"open_issues_count":0,"forks_count":12,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T22:12:59.770Z","etag":null,"topics":["ksuid","rust","svix"],"latest_commit_sha":null,"homepage":"https://www.svix.com","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/svix.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-29T15:06:54.000Z","updated_at":"2025-03-26T04:07:47.000Z","dependencies_parsed_at":"2024-02-29T14:47:21.618Z","dependency_job_id":"1ac55129-2d1e-422d-b7f8-bd62f728874a","html_url":"https://github.com/svix/rust-ksuid","commit_stats":{"total_commits":29,"total_committers":3,"mean_commits":9.666666666666666,"dds":"0.10344827586206895","last_synced_commit":"082ba13823b63c2ce016d18ac7f8543f5c0e0468"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svix%2Frust-ksuid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svix%2Frust-ksuid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svix%2Frust-ksuid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svix%2Frust-ksuid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svix","download_url":"https://codeload.github.com/svix/rust-ksuid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261609,"owners_count":20910108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ksuid","rust","svix"],"created_at":"2024-11-05T20:04:03.185Z","updated_at":"2025-04-04T23:08:50.574Z","avatar_url":"https://github.com/svix.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003ca href=\"https://www.svix.com\"\u003e\n    \u003cimg width=\"120\" src=\"https://avatars.githubusercontent.com/u/80175132?s=200\u0026v=4\" /\u003e\n    \u003cp align=\"center\"\u003eSvix - Webhooks as a service\u003c/p\u003e\n  \u003c/a\u003e\n\u003c/h1\u003e\n\n# Svix-KSUID (Rust)\n\nA pure Rust and fully tested KSUID implementation\n\n![GitHub tag](https://img.shields.io/github/tag/svix/rust-ksuid.svg)\n[![Crates.io](https://img.shields.io/crates/v/svix-ksuid)](https://crates.io/crates/svix-ksuid)\n[![Build Status](https://github.com/svix/rust-ksuid/workflows/CI/badge.svg)](https://github.com/svix/rust-ksuid/actions)\n[![Security audit](https://github.com/svix/rust-ksuid/actions/workflows/security.yml/badge.svg)](https://github.com/svix/rust-ksuid/actions/workflows/security.yml)\n[![docs.rs](https://docs.rs/svix-ksuid/badge.svg)](https://docs.rs/svix-ksuid/)\n[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)\n[![Join our slack](https://img.shields.io/badge/Slack-join%20the%20community-blue?logo=slack\u0026style=social)](https://www.svix.com/slack/)\n\nThis library is fully compatible with [Segment's KSUID](https://segment.com/blog/a-brief-history-of-the-uuid/) implementation:\nhttps://github.com/segmentio/ksuid\n\nFor the Python version, please check out https://github.com/svix/python-ksuid\n\n## What is a ksuid?\n\nA ksuid is a K sorted UID. In other words, a KSUID also stores a date component, so that ksuids can be approximately \nsorted based on the time they were created. \n\nRead more [here](https://segment.com/blog/a-brief-history-of-the-uuid/).\n\n## Usage\n\nAdd the dependency:\n\n```toml\n[dependencies]\nsvix-ksuid = \"^0.6.0\"\n```\n\n```rust\nuse svix_ksuid::*;\n\nlet ksuid = Ksuid::new(None, None);\nprintln!(\"{}\", ksuid.to_string());\n// 1srOrx2ZWZBpBUvZwXKQmoEYga2\n```\n\n### Higher timestamp accuracy mode\n\nKsuids have a 1 second accuracy which is not sufficient for all use-cases. That's why this library exposes a higher accuracy mode which supports accuracy of up to 4ms.\n\nIt's fully compatible with normal ksuids, in fact, it outputs valid ksuids. The difference is that it sacrifices one byte of the random payload in favor of this accuracy.\n\nThe code too is fully compatible:\n\n```rust\nuse svix_ksuid::*;\n\nlet ksuid = KsuidMs::new(None, None);\n```\n\nAnd they both implement the same `KsuidLike` trait.\n\n### Opt-in features\n* `serde` - adds the ability to serialize and deserialize `Ksuid` and `KsuidMs`\n  using serde.\n\nMake sure to enable like this:\n```toml\n[dependencies]\nsvix-ksuid = { version = \"^0.6.0\", features = [\"serde\"] }\n```\n\n## Examples\n\n### Converting Ksuids\n\n```rust\nuse svix_ksuid::*;\n\nlet ksuid = Ksuid::new(None, None);\n\n// Base62\nprintln!(\"{}\", ksuid.to_string()); // also: ksuid.to_base62()\n// 1srOrx2ZWZBpBUvZwXKQmoEYga2\n\n// Bytes (\u0026[u8])\nprintln!(\"{:?}\", ksuid.bytes());\n// [13, 53, 196, 51, 225, 147, 62, 55, 242, 117, 112, 135, 99, 173, 199, 116, 90, 245, 231, 242]\n\n// Timestamp (time::OffsetDateTime)\nprintln!(\"{:?}\", ksuid.timestamp());\n// 2021-05-21T20:04:03Z\n\n// Timestamp (seconds)\nprintln!(\"{}\", ksuid.timestamp_seconds());\n1621627443\n\n// Payload (\u0026[u8])\nprintln!(\"{:?}\", ksuid.bytes());\n// [225, 147, 62, 55, 242, 117, 112, 135, 99, 173, 199, 116, 90, 245, 231, 242]\n```\n\n### Create Ksuids\n\n```rust\nuse svix_ksuid::*;\n\n// Timestamp is now, payload is randomly generated\nlet ksuid = Ksuid::new(None, None);\n\n// Explicitly set either\nlet bytes = [12u8; Ksuid::PAYLOAD_BYTES];\nlet ksuid = Ksuid::new(Some(Utc::now()), Some(\u0026bytes));\nlet ksuid = Ksuid::new(None, Some(\u0026bytes));\nlet ksuid = Ksuid::new(Some(Utc::now()), None);\n\n// From base62\nlet base62 = \"1srOrx2ZWZBpBUvZwXKQmoEYga2\";\nlet ksuid = Ksuid::from_base62(base62).unwrap();\nlet ksuid = Ksuid::from_str(base62).unwrap(); // Also implement FromStr\n\n// From bytes\nlet bytes = [12u8; 20];\nlet ksuid = Ksuid::from_bytes(bytes.clone());\nassert_eq!(\u0026bytes, ksuid.bytes());\n```\n\n### Compare and order Ksuids\n\n```rust\nuse svix_ksuid::*;\n\nlet ksuid1 = Ksuid::from_seconds(Some(1_555_555_555), None);\nlet ksuid2 = Ksuid::from_seconds(Some(1_777_777_777), None);\n\nassert!(ksuid1 \u003c ksuid2);\nassert!(ksuid1 \u003c= ksuid2);\nassert!(ksuid1 == ksuid1);\nassert!(ksuid2 \u003e ksuid1);\nassert!(ksuid2 \u003e= ksuid1);\n```\n\n### License\n\nksuid source code is available under an MIT [License](./LICENSE).\n\nAll rights reserved to the [Svix webhooks service](https://www.svix.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvix%2Frust-ksuid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvix%2Frust-ksuid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvix%2Frust-ksuid/lists"}