Crates.io | tagged-types |
lib.rs | tagged-types |
version | 0.1.1 |
created_at | 2025-08-29 23:37:21.197847+00 |
updated_at | 2025-08-30 00:12:54.477927+00 |
description | Define strongly typed wrappers over base types with minimal boilerplate |
homepage | |
repository | https://github.com/poroh/tagged-types |
max_upload_size | |
id | 1817073 |
size | 12,121 |
This library contains helpers to enforce stricter types.
This library is designed to depend only on the standard library.
Optionally, it supports serialization and deserialization for the underlying type
(see the serde_support
feature).
In many cases, we want strict types, but we don't want to spend a lot of time implementing boilerplate around them (serialization / deserialization / parsing / clone / copy, etc.).
This library makes it possible to introduce types with minimal effort and implements many traits for the new type when the underlying type implements them.
Let:
V
is the value typeT
is the tag typeAlways implemented traits:
Deref
is implemented, so all methods of V
are available on
TaggedType<V, T>
.Conditionally implemented traits when the trait is implemented by the underlying type V
:
Clone
Copy
Hash
PartialEq
Eq
Default
Conditionally implemented traits when the trait is implemented by the underlying
type V
and enabled for the tag type T
:
Debug
if T
implements TransparentDebug
. In this case, Debug
formats the same as V
Display
if T
implements TransparentDisplay
. In this case,
Display
formats the same as V
FromStr
if T
implements TransparentFromStr
. In this case,
FromStr
parses the same as V
Conditional feature support:
serde_support
:Conditionally implemented traits when implemented by the underlying type
V
:
Serialize
Deserialize