#newtype #wrapper #dont

no-std trapper

A library for creating newtypes that don't require ownership of their internal value

2 stable releases

2.0.0 Aug 1, 2019
1.0.0 Jul 30, 2019

#350 in No standard library


Used in trapper_macro

MIT license

7KB

trapper

A simple Rust library for creating transparent newtypes that don't require ownership to be used.

Example

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));

lib.rs:

trapper

Trapper (or transparent wrapper) allows for the creation of transparent type wrappers, that is types which are transparent and can be wrapped and unwrapped for zero cost.

Dependencies

~2MB
~48K SLoC