Crates.io | trapper_macro |
lib.rs | trapper_macro |
version | 1.0.0 |
source | src |
created_at | 2019-08-01 00:27:45.842014 |
updated_at | 2019-08-01 00:27:45.842014 |
description | A proc-macro crate for easily building wrapper types with trapper |
homepage | |
repository | https://github.com/ObsidianMinor/trapper |
max_upload_size | |
id | 153305 |
size | 4,271 |
A simple Rust library for creating transparent newtypes that don't require ownership to be used.
use trapper::{Wrapper, newtype};
newtype!(#[derive(PartialEq, Debug)] type NumberWrapper(i32));
fn foo(r: &i32, m: &mut i32) {
let ref_wrapper: &NumberWrapper = NumberWrapper::wrap_ref(r);
let mut_wrapper: &mut NumberWrapper = NumberWrapper::wrap_mut(m);
}
let mut wrapper = NumberWrapper::wrap(12);
*wrapper.unwrap_mut() = 13;
assert_eq!(wrapper, NumberWrapper::wrap(13));