{"id":27759622,"url":"https://github.com/ssg/trid","last_synced_at":"2025-04-29T11:59:03.012Z","repository":{"id":42196406,"uuid":"479920285","full_name":"ssg/trid","owner":"ssg","description":"Parser and data type for Turkish Citizenship ID numbers","archived":false,"fork":false,"pushed_at":"2023-11-07T00:27:52.000Z","size":60,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-29T11:58:57.578Z","etag":null,"topics":["identity","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ssg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-10T05:16:59.000Z","updated_at":"2025-04-05T08:22:13.000Z","dependencies_parsed_at":"2023-02-10T17:55:13.312Z","dependency_job_id":null,"html_url":"https://github.com/ssg/trid","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2Ftrid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2Ftrid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2Ftrid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2Ftrid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssg","download_url":"https://codeload.github.com/ssg/trid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251498965,"owners_count":21598979,"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":["identity","rust"],"created_at":"2025-04-29T11:59:02.479Z","updated_at":"2025-04-29T11:59:02.990Z","avatar_url":"https://github.com/ssg.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Crates.io](https://img.shields.io/crates/v/trid)](https://crates.io/crates/trid)\r\n[![Build \u0026 Test](https://github.com/ssg/trid/actions/workflows/rust.yml/badge.svg)](https://github.com/ssg/trid/actions/workflows/rust.yml)\r\n\r\n# trid - Turkish Citizenship ID Number crate\r\n\r\nThis is my first ever written Rust code derived from my own [TurkishId](https://github.com/ssg/TurkishId)\r\npackage for .NET. I'm trying to use existing code as an excuse to learn about Rust. Despite constant tackling with error messages, Rust has been extremely impressive so far. (How cool are doc-tests!?)\r\n\r\n# Usage\r\n\r\n## parse\r\n\r\nThe crate provides `TurkishId` type that represents a valid Turkish ID number. It can be instantiated from a string using the `parse()` method of `str` type. `TurkishId` type guarantess that it never contains an invalid Turkish ID number, so there's no need to validate a `TurkishId` once parsed. It can always be passed around safely.\r\n\r\n## is_valid\r\n\r\nYou can just verify whether a string contains a valid Turkish ID or not by calling `is_valid(value: \u0026str)` function.\r\n\r\n## from_seq\r\n\r\nIf you want to generate a Turkish ID from scratch, you can use `from_seq(seq: u32)` function.\r\n\r\n# Internals\r\n\r\nThe type occupies 11 bytes in memory and kept as ASCII representation of the number in order\r\nto make string display conversions fast. The other alternative would be to have it in a 40-bit number which would complicate the string representation.\r\n\r\n# Examples\r\n\r\nValidate a Turkish citizenship ID number:\r\n\r\n```rust\r\nfn main() {\r\n    if trid::is_valid(\"12345678901\") {\r\n        // yayyy!\r\n    }\r\n}\r\n```\r\n\r\nTry parsing a string into `TurkishId`:\r\n\r\n```rust\r\nuse trid::TurkishId;\r\n\r\nfn main() {\r\n    let id : TurkishId = \"12345678901\".parse()?;\r\n}\r\n```\r\n\r\nGenerate infinite number of random but valid Turkish IDs:\r\n\r\n```rust\r\nuse rand::Rng;\r\nuse trid::TurkishId;\r\n\r\nfn main() {\r\n    let mut rng = rand::thread_rng();\r\n    loop {\r\n        let seq: u32 = rng.gen_range(100_000_000..1_000_000_000);\r\n        println!(\"{}\", TurkishId::from_seq(seq).unwrap());\r\n    }\r\n}\r\n```\r\n\r\n# License\r\n\r\nApache License Version 2.0, see LICENSE file for details.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssg%2Ftrid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssg%2Ftrid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssg%2Ftrid/lists"}