cached-pair
A simple library for caching pairs of values. Similar to EitherOrBoth in the itertools crate,
but with an extra assumption that both values are convertible to each other, and the conversion may be non-trivial or expensive.
For example, you can use this library to hold a pair of values that need to be kept in sync, such as a number and its string representation,
or a binary Vec<u8> and its base64 encoded String.
Examples
Basic Usage
use ;
use Infallible;
use ParseIntError;
let converter = fn_converter;
// Create a pair from a left value
let pair = from_left_conv;
// Access values
assert_eq!;
assert_eq!;
// The converted value is now cached
assert_eq!;
Using the From and TryFrom traits
For types that implement TryFrom traits, you can use the default StdConverter.
use Pair;
use Infallible;
// Define types that implement TryFrom for each other
;
;
// Create a pair of `(Small, Large)` using the default StdConverter.
// Left (small) to right (large) conversion is infallible.
let pair = from_left;
assert_eq!;
// Conversion from right (large) to left (small) may fail if the value is too large.
let pair = from_right;
assert!;