https://github.com/bbqsrc/nova
Newtype macros for commonly reused types in Rust.
https://github.com/bbqsrc/nova
dataclass integers macro newtype rust string uuid vector
Last synced: 3 months ago
JSON representation
Newtype macros for commonly reused types in Rust.
- Host: GitHub
- URL: https://github.com/bbqsrc/nova
- Owner: bbqsrc
- License: apache-2.0
- Created: 2021-06-27T21:20:01.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-19T10:32:04.000Z (8 months ago)
- Last Synced: 2025-03-18T17:05:48.030Z (4 months ago)
- Topics: dataclass, integers, macro, newtype, rust, string, uuid, vector
- Language: Rust
- Homepage: https://docs.rs/nova/
- Size: 38.1 KB
- Stars: 4
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# nova
[](https://docs.rs/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
```toml
[dependencies]
nova = "0.4"
```### Example
```rust
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
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or )
* MIT license ([LICENSE-MIT](LICENSE-MIT) or )at your option.