Crates.io | newtyperef |
lib.rs | newtyperef |
version | 0.4.0 |
source | src |
created_at | 2024-09-17 16:28:26.212057 |
updated_at | 2024-09-19 07:22:41.637066 |
description | generate custom newtype reference types |
homepage | |
repository | https://github.com/zahash/newtyperef/ |
max_upload_size | |
id | 1377687 |
size | 16,251 |
███╗ ██╗███████╗██╗ ██╗████████╗██╗ ██╗██████╗ ███████╗██████╗ ███████╗███████╗ ████╗ ██║██╔════╝██║ ██║╚══██╔══╝╚██╗ ██╔╝██╔══██╗██╔════╝██╔══██╗██╔════╝██╔════╝ ██╔██╗ ██║█████╗ ██║ █╗ ██║ ██║ ╚████╔╝ ██████╔╝█████╗ ██████╔╝█████╗ █████╗ ██║╚██╗██║██╔══╝ ██║███╗██║ ██║ ╚██╔╝ ██╔═══╝ ██╔══╝ ██╔══██╗██╔══╝ ██╔══╝ ██║ ╚████║███████╗╚███╔███╔╝ ██║ ██║ ██║ ███████╗██║ ██║███████╗██║ ╚═╝ ╚═══╝╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ------------------------------------------------------------------------------ Generate custom newtype reference types
include it in your Cargo.toml
under [dependencies]
newtyperef = "*"
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();
}
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();
}
M. Zahash – zahash.z@gmail.com
Distributed under the MIT license. See LICENSE
for more information.
newtyperef
!git checkout -b feature/fooBar
)git commit -am 'Add some fooBar'
)git push origin feature/fooBar
)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
.