9 releases

0.5.4 Aug 12, 2022
0.5.3 Jan 20, 2022
0.5.2 Dec 4, 2021
0.5.1 Nov 25, 2021
0.3.1 Aug 15, 2021

#876 in Procedural macros

Download history 49/week @ 2024-01-04 42/week @ 2024-01-11 119/week @ 2024-01-18 63/week @ 2024-01-25 56/week @ 2024-02-01 64/week @ 2024-02-08 108/week @ 2024-02-15 98/week @ 2024-02-22 70/week @ 2024-02-29 61/week @ 2024-03-07 122/week @ 2024-03-14 107/week @ 2024-03-21 79/week @ 2024-03-28 89/week @ 2024-04-04 52/week @ 2024-04-11 36/week @ 2024-04-18

269 downloads per month
Used in 2 crates (via nova-macro)

Apache-2.0 OR MIT

10KB
289 lines

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.


lib.rs:

This crate implements the macro for nova and should not be used directly.

Dependencies

~1.5MB
~41K SLoC