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:
- It's simplier to use for well known types, simply add
#[id]
to your struct - The defaults provide a lot of blanket implementations that might be missed when doing it manually
- Some features provided don't have corresponding derive macros (
AsBytes
,AsRef
,Borrow
) - All trivial functions are marked inline
Defaults
/NoDefaults
: Enable or disable defaults for known typesClone
/NoClone
: Enable or disable derivingstd::clone::Clone
Hash
/NoHash
: Enable or disable derivingstd::hash::Hash
PartialEq
/NoPartialEq
: Enable or disable derivingstd::cmp::PartialEq
Eq
/NoEq
: Enable or disable derivingstd::cmp::Eq
PartialOrd
/NoPartialOrd
: Enable or disable derivingstd::cmp::PartialOrd
Ord
/NoOrd
: Enable or disable derivingstd::cmp::Ord
Display
/NoDisplay
: Enable or disable derivingstd::fmt::Display
and adding ato_string
methodDebug
/NoDebug
: Enable or disable derivingstd::fmt::Debug
AsBytes
/NoAsBytes
: Enable or disable derivingstd::convert::AsRef<[u8]>
and adding aas_bytes
methodBorrow
/NoBorrow
: Enable or disable derivingstd::borrow::Borrow
AsRef
/NoAsRef
: Enable or disable derivingstd::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);