https://github.com/tylerbloom/typedid
Make your IDs strongly typed!!
https://github.com/tylerbloom/typedid
Last synced: about 1 month ago
JSON representation
Make your IDs strongly typed!!
- Host: GitHub
- URL: https://github.com/tylerbloom/typedid
- Owner: TylerBloom
- License: lgpl-2.1
- Created: 2022-08-29T14:30:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-22T16:02:39.000Z (over 2 years ago)
- Last Synced: 2025-04-10T08:11:57.734Z (about 2 months ago)
- Language: Rust
- Size: 23.4 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://crates.io/crates/typed_id)
[](https://docs.rs/typed_id/)

[](https://codecov.io/gh/TylerBloom/TypedId)
## About
`TypedId` introduces a single type, aptly named `TypedId`. This is a generic
wrapper any type, often types that you would use as an identifier. However,
each instance of a `TypedId` has a free-generic parameter that you can use to
associate that ID type to a given struct (or collection of structs).This allows you to have an added layer of type-checked safety at compile time
that disappears at run time! You can have all your types use the same
underlying structure for their identifiers while never have to worry about
swapping them around.## How it Works
`TypedId`s are very straightforward.
The easiest way to use them is why declaring your own `type`s that use `TypedId`.
For example,
```rust
use typed_id::TypedId;pub struct Customer {
id: CustomerId,
/* Likely other fields */
}pub type CustomerId = TypedId;
```It's that simple! If you have other types that you need ids for, simply add
another `type` and `TypedId` will handle all the boilerplate for you!Note, that `TypedId` has an optional dependency on `serde`. When enabled, this
adds an opinionated (de)serialization implementation. This implementation
(de)serializes a `TypedId` as its underlying type.## Why use
Rust has a very powerful type system with many amazing properties. This
leverages that system to prevent simple typos, such as passing in the wrong
type to a function.## Contribution
If you want to contribute to or improve upon this library, please do so.
Fork this project or submit an issue or a pull request for a
feature/fix/change/etc. All that I ask is for derived/iterative
libraries to be open and free to use and ideally with the same license
(LGPL v2.1). Any other application or library that uses this library can
use any license.