| Crates.io | stidgen |
| lib.rs | stidgen |
| version | 0.1.1 |
| created_at | 2021-08-09 21:25:06.342654+00 |
| updated_at | 2021-08-15 16:44:04.92725+00 |
| 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::CloneHash/NoHash: Enable or disable deriving std::hash::HashPartialEq/NoPartialEq: Enable or disable deriving std::cmp::PartialEqEq/NoEq: Enable or disable deriving std::cmp::EqPartialOrd/NoPartialOrd: Enable or disable deriving std::cmp::PartialOrdOrd/NoOrd: Enable or disable deriving std::cmp::OrdDisplay/NoDisplay: Enable or disable deriving std::fmt::Display and adding a to_string methodDebug/NoDebug: Enable or disable deriving std::fmt::DebugAsBytes/NoAsBytes: Enable or disable deriving std::convert::AsRef<[u8]> and adding a as_bytes methodBorrow/NoBorrow: Enable or disable deriving std::borrow::BorrowAsRef/NoAsRef: Enable or disable deriving std::convert::AsRefFor 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);