Newtype macros for commonly reused types in Rust.
APACHE-2.0 License
Create newtypes with great convenience.
All types generated by the following macros implement Debug
, Clone
, Eq
, PartialEq
, Ord
, PartialOrd
and Hash
. For Copy
types, the newtype also implements Copy
.
[dependencies]
nova = "0.4"
use nova::newtype;
#[newtype(serde, borrow = "str")]
pub type Meow = String;
#[newtype(new, copy)]
pub(crate) type SpecialUuid = uuid::Uuid;
fn example() {
let meow = Meow("this is a string".to_string());
let special_uuid = SpecialUuid::from(uuid::Uuid::new_v4());
// Get inner:
let inner = special_uuid.into_inner();
}
serde
attribute to derive Serialize
and Deserialize
for newtypes.sqlx
attribute to derive sqlx::Type
for newtypes.async_graphql
attribute to implement Scalar
for newtypes.Copy
on the newtype.Deref
and into_inner
functions to create an opaque type.Deref
implementation, if needed.new
function and From
implementation.#[derive(...)]
attribute.This project is licensed under either of
at your option.