tagged-id
A zero-cost wrapper adding type-safety to ressource identifiers.
Why ?
This solves two problems:
- If two ressources are identified by the same type (a
Userand aDeviceboth being identified by ai32for instance), they might be swapped by mistake in application code. The compiler cannot help you with this, but it is of course incorrect. - When writting code that needs to manipulate ressource identifiers, you often need to lookup what the concrete type of the ID is in order to write function signatures and type annotations. In most cases, the nature of the ID does not matter, so it is more convenient to just treat it as an opaque type.
Examples
use ;
Id<T> inherits core trait implementations of the inner type. For instance, if InnerId is Copy, then Id<T> is also Copy.
Id<T> is just a newtype wrapper of the inner type with a trait bound, which makes it a zero cost abstraction.
Cargo Feature Flags
smartstring: EnableFrom<&str>instance converting to aCompactString. When disabled, an instance forStringis enabled instead.serde: Enable serde support fortagged-idand dependencies that support it likesmartstring.sqlx-{postgres,mysql,sqlite}: EnableEncodeandDecodeinstances for transparent use with the correspondingsqlxbackend.