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 |
#22 in #nova
Used in nova
12KB
300 lines
This crate implements the macro for nova and should not be used directly.
nova
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
serdeattribute to deriveSerializeandDeserializefor newtypes. - sqlx: enables support for the
sqlxattribute to derivesqlx::Typefor newtypes. - async_graphql: enables support for the
async_graphqlattribute to implementScalarfor newtypes.
Generation attributes
- copy: derives
Copyon the newtype. - opaque: disables generating a
Derefandinto_innerfunctions to create an opaque type. - borrow = "<type>": sets the type to be used for the
Derefimplementation, if needed. - new: create default construction
newfunction andFromimplementation. - 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
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Dependencies
~2MB
~48K SLoC