Make your IDs strongly typed!!

Overview

Crates.io Documentation GitHub Workflows Coverage Status Maintenance

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

TypedIds are very straightforward. The easiest way to use them is why declaring your own types that use TypedId. For example,

use typed_id::TypedId;

pub struct Customer {
    id: CustomerId,
    /* Likely other fields */
}

pub type CustomerId = TypedId<u32, Customer>;

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.

You might also like...
cargo-add command to make dependencies into dylibs

cargo add-dynamic This cargo command allows to wrap dependencies as dylibs. For why you might want this see Speeding up incremental Rust compilation w

A collection of crates to make minecraft development (client, server) with rust possible.

rust-craft rust-craft is a collection of crates to make minecraft development (client, server) with rust possible. Motivation There's no better way of

Aim is to make PCBoard clone that's finished on PCboards 100th birthday
Aim is to make PCBoard clone that's finished on PCboards 100th birthday

icy_board Aim is to make PCBoard clone that's finished on PCboards 100th birthday - for sure it'll take much time. I've started to port a PPL decompil

A cli tool to write your idea in terminal
A cli tool to write your idea in terminal

Ideas ideas is a cli tools to write your idea in your terminal. Demo Features tagged idea, contains tips, idea, todo status switch ascii icon write yo

Take your first step in writing a compiler. Implemented in Rust.

first-step-rust Take your first step in writing a compiler, using Rust. Building from Source Make sure the Rust toolchain is installed on your compute

Some UwU and OwO for your Rust code

UwU Types Some UwU and OwO for your Rust code This is a Rust crate inspired by this tweet from @thingskatedid / @katef. Credits Some extra functionali

Notifications for your Argo Workflows.
Notifications for your Argo Workflows.

Hermes -- notifications for Argo Workflows Hermes aims to provide a streamlined way of sending notifications to various messaging services from your A

A complicated eso-lang written in Rust that doesn't limit your creativity!

Documentation for mott Introduction mott (from french "mot" = word) is (maybe) the first programming language, that doesn't limit your creativity to p

qfetch is a tool that fetches info about your linux install.

qfetch qfetch is a tool that fetches info about your linux install. Status Dependencies /proc/meminfo with the following fields: MemTotal in the 1st l

Owner
Tyler Bloom
Avid Rustacean. Software Engineer at @Fortanix. Primary software architect for @MonarchDevelopment. MS in Math from the University of Vermont
Tyler Bloom
A typed map which can make sure item exist.

Certain Map A typed map which can make sure item exist. What Problem Does It Solve In Rust, we often use Service abstraction for modular structure des

ihc童鞋@提不起劲 27 Jun 26, 2023
Rust crate implementing short & stable ids based on timestamps

Lexicoid Short & stable IDs based on timestamps. Heavily inspired by Short, friendly base32 slugs from timestamps by @brandur. Install Install with ca

Luciano Mammino 6 Jan 29, 2023
A statically-typed, interpreted programming language, with generics and type inference

Glide A programming language. Currently, this includes: Static typing Generics, with monomorphization Type inference on function calls func identity<T

Patrick Gu 1 Apr 10, 2022
A small, nutty dependently typed language.

pistachio I want to learn about how theorem provers and dependently typed languages are implemented. This is a little repo for experimentation. elabor

McCoy R. Becker 8 Nov 11, 2022
The compiler for Gera, a statically typed and garbage collected programming language.

Gera The compiler for Gera, a satically typed and garbage collected programming language. Currently WIP (Work in progress). Progress This is a rough o

null 4 Oct 26, 2023
Make and use playgrounds locally.

cargo playground Cargo playground opens a local playground in the editor of your choice. Install You can install it directly using cargo $ cargo insta

null 18 Jan 3, 2023
A tool to make grocery lists written in Rust

grusterylist: makes grocery lists, written in Rust grusterylist uses and can add to local libraries of user-added recipes and grocery items to put tog

null 3 Jun 17, 2022
Make a .scratch directory to keep random scribbles in

mkscratch Creates a directory named .scratch in your current working directory which will be ignored by Git. Useful for keeping around miscellaneous f

Kayla 3 Oct 21, 2022
A webring of people who make cool stuff. technology, music, art, writing, anything goes!

a webring of people who make cool stuff. technology, music, art, writing, anything goes!

Kognise 44 Dec 6, 2022
rust database for you to use and help me make!

Welcome To Rust Database! What is this? this is a database for you to git clone and use in your project! Why should i use it? It is fast and it takes

Carghai74 2 Dec 4, 2022