cmp_wrap

Have you ever needed to compare the same data by different fields, depending on context? If so, this crate is for you!

Example

Using context

You probably have some kind of context in which you would like to compare your values, such as length of vectors or the first value.

```rust use cmp_wrap::KeyCmpContext;

let by_length = KeyCmpContext::new(&|v: &Vec<_>| v.len());

let longvec = bylength.wrap(vec![1,2,3,4]); let shortvec = bylength.wrap(vec![1,2]);

assert!(longvec > shortvec, "The vec {:?} is longer then {:?}", longvec, shortvec);

```

By direct creation

you can define the key function on a "case by case" basis. ```rust use cmp_wrap::CmpByKey;

let lenaskey = |v: &Vec<_>| v.len();

let longvec = CmpByKey::new(vec![1,2,3,4], &lenaskey); let shortvec = CmpByKey::new(vec![1,2], &lenaskey);

assert!(longvec > shortvec, "The vector {:?} is longer then {:?}", longvec, shortvec); ```

License: MIT