https://github.com/naokim03/derive_newtype
This derive macro provides Deref, DerefMut, and From for the newtype pattern.
https://github.com/naokim03/derive_newtype
crate derive macro newtype
Last synced: over 1 year ago
JSON representation
This derive macro provides Deref, DerefMut, and From for the newtype pattern.
- Host: GitHub
- URL: https://github.com/naokim03/derive_newtype
- Owner: NaokiM03
- License: mit
- Created: 2022-05-03T01:38:55.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-03T13:35:08.000Z (about 4 years ago)
- Last Synced: 2025-01-29T04:19:47.175Z (over 1 year ago)
- Topics: crate, derive, macro, newtype
- Language: Rust
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# derive_newtype
## About
This derive macro provides `Deref`, `DerefMut`, and `From` for the newtype pattern.
A similar crate exists but has not been updated.
## Notice
This library has no plans to add further functionality at this time. Only version updates of dependent libraries will be followed.
## How to use
```rust
use derive_newtype::Newtype;
#[derive(Newtype)]
struct Foo(u8);
```
This macro will generate the following code:
```rust
impl core::ops::Deref for Foo {
type Target = u8;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl core::ops::DerefMut for Foo {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl From for Foo {
fn from(inner: u8) -> Foo {
Foo(inner)
}
}
```
## License
derive_newtype is released under the MIT License