{"id":50939181,"url":"https://github.com/iddm/strict-typing","last_synced_at":"2026-06-17T12:02:23.860Z","repository":{"id":351173266,"uuid":"1209867084","full_name":"iddm/strict-typing","owner":"iddm","description":null,"archived":false,"fork":false,"pushed_at":"2026-04-13T21:36:38.000Z","size":14,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-31T06:41:52.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iddm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-13T21:29:32.000Z","updated_at":"2026-05-26T22:11:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/iddm/strict-typing","commit_stats":null,"previous_names":["iddm/strict-typing"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iddm/strict-typing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Fstrict-typing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Fstrict-typing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Fstrict-typing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Fstrict-typing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iddm","download_url":"https://codeload.github.com/iddm/strict-typing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iddm%2Fstrict-typing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34447266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2026-06-17T12:02:23.008Z","updated_at":"2026-06-17T12:02:23.850Z","avatar_url":"https://github.com/iddm.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# strict-typing\n\n[![Crates.io](https://img.shields.io/crates/v/strict-typing.svg)](https://crates.io/crates/strict-typing)\n[![Documentation](https://docs.rs/strict-typing/badge.svg)](https://docs.rs/strict-typing)\n[![License: MIT](https://img.shields.io/crates/l/strict-typing.svg)](https://opensource.org/licenses/MIT)\n\nA Rust procedural macro that enforces strict typing on struct fields, enum variants, function signatures, trait definitions, and impl blocks. It prevents the use of bare primitive types, encouraging newtype wrappers for clarity and safety.\n\nRust is all about correctness in my humble opinion. And I want it to stay that way\nin my personal experience. I think this is how Rust should have been made. This\nshould be a compiler built-in.\n\n## Motivation\n\nBare primitives like `u32` or `bool` compile fine but carry no domain meaning. A `u32` could be a user ID, a pixel count, or a port number — the type system won't stop you from mixing them up. Newtype wrappers (`struct UserId(u32)`) make intent explicit and catch misuse at compile time.\n\nIn my projects, I always create the transparent newtypes that **precisely** define what they carry.\nIf I ever need to, I also create only the correct versions of conversions between such and other types.\n\nOriginally wrote for my own projects, I decided to share it with others. Enjoy.\n\n`#[strict_types]` turns this from a convention into a compiler-enforced rule.\n\nP.S. I decided to name the project `strict-typing` initially with the intention to\nextend its functionality.\n\n## Usage\n\nAdd the dependency:\n\n```toml\n[dependencies]\nstrict-typing = \"0.1\"\n```\n\n### Basic — reject primitives in struct fields\n\n```rust\nuse strict_typing::strict_types;\n\nstruct Percentage(u8);\nstruct Label(String);\n\n#[strict_types]\nstruct Config {\n    ratio: Percentage, // OK — newtype wrapper\n    name: Label,       // OK\n    // count: u32,     // compile error: disallowed type `u32`\n}\n```\n\n### Enums\n\n```rust\nuse strict_typing::strict_types;\n\nstruct Velocity(f64);\n\n#[strict_types]\nenum Event {\n    Click { x: Velocity, y: Velocity },\n    Disconnect,\n    // Resize(u32, u32), // compile error\n}\n```\n\n### Functions, traits, and impl blocks\n\n```rust\nuse strict_typing::strict_types;\n\nstruct Distance(f64);\nstruct Speed(f64);\nstruct Duration(f64);\n\n#[strict_types]\nfn compute_speed(d: Distance, t: Duration) -\u003e Speed {\n    Speed(d.0 / t.0)\n}\n```\n\n### Extending the disallow list\n\nBy default, all numeric primitives plus `bool` and `char` are disallowed. Add more with `disallow(...)`:\n\n```rust\nuse strict_typing::strict_types;\n\n/// # Strictness\n///\n/// - [String] disallowed because domain names should use a newtype.\n#[strict_types(disallow(String))]\nstruct Name {\n    // value: String, // compile error\n}\n```\n\n### Allowing specific primitives\n\nRemove types from the default disallow list with `allow(...)`:\n\n```rust\nuse strict_typing::strict_types;\n\n/// # Strictness\n///\n/// - [bool] allowed here because a simple flag is sufficient.\n#[strict_types(allow(bool))]\nstruct Flags {\n    enabled: bool, // OK\n}\n```\n\n### Documentation requirement\n\nWhen using `allow(...)` or `disallow(...)`, you must document each override in a `/// # Strictness` doc section. This forces authors to justify every exception, keeping the decision visible in code review.\n\n## Default disallowed types\n\n`u8` `u16` `u32` `u64` `u128` `usize` `i8` `i16` `i32` `i64` `i128` `isize` `f32` `f64` `bool` `char`\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiddm%2Fstrict-typing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiddm%2Fstrict-typing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiddm%2Fstrict-typing/lists"}