#libary #wrapping #traits

wrappr

A libary for some useful wrapping traits

4 stable releases

1.2.0 Mar 25, 2024
1.1.1 Mar 23, 2024
1.0.0 Mar 23, 2024

#3 in #wrapping

Download history 218/week @ 2024-03-17 163/week @ 2024-03-24 90/week @ 2024-03-31

471 downloads per month

MIT license

12KB
214 lines

Wrappr

wrappr is a libary for some useful wrapping traits

the 4 trait groups are as follows:

  • a wrapper is a cheap wrapper that constructs a new type, generic over the input type
  • a composer is a potentially costly operation that takes a generic input type, and composes it within itself
  • a injectable is the semantic opposite of a wrapper, it is automatically implemented and is just the object and generic swapped
  • a embedable is the semantic opposite of a composer, it is automatically implemented and is just the object and generic swapped

Examples

Wrapper

let x: u8 = 1;
let y: u8 = 2;
let z: Vec<u8> = vec![3, 4];

let yz: Vec<u8> = y.wrap(z);
assert_eq!(yz, vec![2, 3, 4]);

let xyz: Vec<u8> = x.wrap(yz);
assert_eq!(xyz, vec![1, 2, 3, 4]);

Composer

let mut x: Vec<u8> = vec![1, 2];
let y: Vec<u8> = vec![3, 4];
let z: u8 = 5;

x.compose(y);
assert_eq!(x, vec![1, 2, 3, 4]);

x.compose(z);
assert_eq!(x, vec![1, 2, 3, 4, 5]);

Injectable

let x: u8 = 1;
let y: u8 = 2;
let z: Vec<u8> = vec![3, 4];

let yz: Vec<u8> = z.inject(y);
assert_eq!(yz, vec![2, 3, 4]);

let xyz: Vec<u8> = yz.inject(x);
assert_eq!(xyz, vec![1, 2, 3, 4]);

Embedable

let mut x: Vec<u8> = vec![1, 2];
let y: Vec<u8> = vec![3, 4];
let z: u8 = 5;

y.embed(&mut x);
assert_eq!(x, vec![1, 2, 3, 4]);

z.embed(&mut x);
assert_eq!(x, vec![1, 2, 3, 4, 5]);

No runtime deps