8 releases (4 breaking)

new 0.5.1 Nov 25, 2021
0.5.0 Nov 25, 2021
0.4.0 Oct 22, 2021
0.3.2 Oct 5, 2021
0.1.0 Jun 27, 2021

#739 in Rust patterns

Download history 34/week @ 2021-08-09 35/week @ 2021-08-16 1/week @ 2021-08-30 7/week @ 2021-09-13 3/week @ 2021-09-20 7/week @ 2021-09-27 23/week @ 2021-10-04 22/week @ 2021-10-11 58/week @ 2021-10-18 26/week @ 2021-10-25 3/week @ 2021-11-01 10/week @ 2021-11-08 5/week @ 2021-11-15 56/week @ 2021-11-22

66 downloads per month

Apache-2.0 OR MIT

8KB

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.

License

This project is licensed under either of

at your option.

Dependencies

~0.6–1MB
~24K SLoC

a