4 releases (breaking)
0.4.0 | Sep 19, 2024 |
---|---|
0.3.0 | Sep 18, 2024 |
0.2.0 | Sep 17, 2024 |
0.1.0 | Sep 17, 2024 |
#327 in Procedural macros
124 downloads per month
10KB
102 lines
███╗ ██╗███████╗██╗ ██╗████████╗██╗ ██╗██████╗ ███████╗██████╗ ███████╗███████╗ ████╗ ██║██╔════╝██║ ██║╚══██╔══╝╚██╗ ██╔╝██╔══██╗██╔════╝██╔══██╗██╔════╝██╔════╝ ██╔██╗ ██║█████╗ ██║ █╗ ██║ ██║ ╚████╔╝ ██████╔╝█████╗ ██████╔╝█████╗ █████╗ ██║╚██╗██║██╔══╝ ██║███╗██║ ██║ ╚██╔╝ ██╔═══╝ ██╔══╝ ██╔══██╗██╔══╝ ██╔══╝ ██║ ╚████║███████╗╚███╔███╔╝ ██║ ██║ ██║ ███████╗██║ ██║███████╗██║ ╚═╝ ╚═══╝╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ------------------------------------------------------------------------------ Generate custom newtype reference types
🚀 Installation
include it in your Cargo.toml
under [dependencies]
newtyperef = "*"
🧑💻 Usage examples
Basic Usage
use newtyperef::newtyperef;
#[newtyperef]
pub struct Name(pub String);
fn main() {
let mut name = Name("X Æ A-12".into());
let name_ref: NameRef<'_> = name.as_ref();
let name_ref_inner: &String = name_ref.deref();
let mut name_mut: NameRefMut<'_> = name.as_mut();
let name_mut_inner: &String = name_mut.deref();
let name_mut_inner: &mut String = name_mut.deref_mut();
}
Customizing Reference Types
use newtyperef::newtyperef;
#[newtyperef(ref = str, mut = str)]
pub struct Name(pub String);
fn name_example() {
let mut name = Name("X Æ A-12".into());
let name_ref: NameRef<'_> = name.as_ref();
let name_ref_inner: &str = name_ref.deref();
let mut name_mut: NameRefMut<'_> = name.as_mut();
let name_mut_inner: &str = name_mut.deref();
let name_mut_inner: &mut str = name_mut.deref_mut();
}
#[newtyperef(ref = [String])]
pub struct Emails(pub Vec<String>);
fn emails_example() {
let mut emails = Emails(vec!["a@a.com".into(), "b@b.com".into()]);
let emails_ref: EmailsRef<'_> = emails.as_ref();
let emails_ref_inner: &[String] = emails_ref.deref();
let mut emails_mut: EmailsRefMut<'_> = emails.as_mut();
let emails_mut_inner: &Vec<String> = emails_mut.deref();
let emails_mut_inner: &mut Vec<String> = emails_mut.deref_mut();
}
🌟 Connect with Us
M. Zahash – zahash.z@gmail.com
Distributed under the MIT license. See LICENSE
for more information.
🤝 Contribute to newtyperef
!
- Fork it (https://github.com/zahash/newtyperef/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
❤️ Show Some Love!
If you find newtyperef
helpful and enjoy using it, consider giving it a ⭐ on GitHub! Your star is a gesture of appreciation and encouragement for the continuous improvement of newtyperef
.
Dependencies
~245–700KB
~17K SLoC