kubetsu: distinguish value type of other struct
This is a library that distinguish struct value type as other type value.
kubetsu (区別) means distinguish in Japanese.
Usage
Define your own ID type using the define_id! macro. Different type tags prevent accidental misuse at compile time.
define_id!;
;
;
type UserId = ;
type ItemId = ;
define_id!;
;
type UserId = ;
let user_id = new;
// you can access original value reference with `inner()`.
assert_eq!;
// you can use `==` that have same value.
assert_eq!;
The generated type implements Debug, PartialEq, Eq, Hash, Clone, and From<InnerType>.
You can also generate a concrete type with a fixed inner type:
define_id!;
let user_id = new;
assert_eq!;
serde support
Use the kubetsu-serde crate to serialize and deserialize as the inner value.
define_id!;
impl_serde!;
sqlx support
Use the kubetsu-sqlx crate to encode and decode ID values with sqlx. Enable the feature for each driver you need (any, mysql, postgres, sqlite).
define_id!;
impl_sqlx!;
async
fake support
Use the kubetsu-fake crate to generate dummy values with fake.
define_id!;
impl_fake!;
use ;
Install
License
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) see LICENSE
Copyright (c) 2024 Keiji Yoshimi