nova

Crates.ionova
lib.rsnova
version0.5.4
sourcesrc
created_at2021-06-27 21:20:19.145296
updated_at2022-08-12 09:39:44.881971
descriptionMacro to derive newtypes with support for serde and sqlx.
homepage
repositoryhttps://github.com/bbqsrc/nova
max_upload_size
id415519
size16,384
Brendan Molloy (bbqsrc)

documentation

README

nova

Documentation

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.

Usage

[dependencies]
nova = "0.4"

Example

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();
}

Supported attributes

Crate compatibility attributes

  • serde: enables support for the serde attribute to derive Serialize and Deserialize for newtypes.
  • sqlx: enables support for the sqlx attribute to derive sqlx::Type for newtypes.
  • async_graphql: enables support for the async_graphql attribute to implement Scalar for newtypes.

Generation attributes

  • copy: derives Copy on the newtype.
  • opaque: disables generating a Deref and into_inner functions to create an opaque type.
  • borrow = "<type>": sets the type to be used for the Deref implementation, if needed.
  • new: create default construction new function and From implementation.
  • derive(...): replace the default derives for the newtype with the provided list. Same syntax as the normal #[derive(...)] attribute.

License

This project is licensed under either of

at your option.

Commit count: 38

cargo fmt