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 with the Converter
You can define a converter between the two types, and use it to create a Pair.
use ;
use Infallible;
use ParseIntError;
// Define a converter between i32 and String
;
// Create a pair with a custom converter
let pair = from_left_conv;
// Access values
assert_eq!;
assert_eq!;
// The converted value is now cached
assert_eq!;
Using Function Converters
You can also use the fn_converter function to create a converter from closures.
use ;
use Infallible;
// Create a converter using closures
let converter = fn_converter;
let pair = from_left_conv;
assert_eq!;