Crates.io | stidgen |
lib.rs | stidgen |
version | 0.1.1 |
source | src |
created_at | 2021-08-09 21:25:06.342654 |
updated_at | 2021-08-15 16:44:04.92725 |
description | Strongly Typed ID types macro |
homepage | https://github.com/vbfox/stidgen.rs |
repository | https://github.com/vbfox/stidgen.rs |
max_upload_size | |
id | 433987 |
size | 43,818 |
A macro to simplify usage of srongly type ID types instead of plain
String
, u64
or Guid
in Rust codebases.
use stidgen::{Id, id};
#[id]
pub struct UserId(String);
#[id(NoDefaults, Format, Debug)]
pub struct UserId(u64);
While the derive
macro can already be used to achieve most of what this
macro proposes using it has the following advantages:
#[id]
to your structAsBytes
, AsRef
, Borrow
)Defaults
/NoDefaults
: Enable or disable defaults for known typesClone
/NoClone
: Enable or disable deriving std::clone::Clone
Hash
/NoHash
: Enable or disable deriving std::hash::Hash
PartialEq
/NoPartialEq
: Enable or disable deriving std::cmp::PartialEq
Eq
/NoEq
: Enable or disable deriving std::cmp::Eq
PartialOrd
/NoPartialOrd
: Enable or disable deriving std::cmp::PartialOrd
Ord
/NoOrd
: Enable or disable deriving std::cmp::Ord
Display
/NoDisplay
: Enable or disable deriving std::fmt::Display
and adding a to_string
methodDebug
/NoDebug
: Enable or disable deriving std::fmt::Debug
AsBytes
/NoAsBytes
: Enable or disable deriving std::convert::AsRef<[u8]>
and adding a as_bytes
methodBorrow
/NoBorrow
: Enable or disable deriving std::borrow::Borrow
AsRef
/NoAsRef
: Enable or disable deriving std::convert::AsRef
For unknown types all features are disabled by default but some types like String
have smart defaults.
#[id(Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Display, ToString, Debug, AsBytes, ...)]
pub struct Id(String);