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 Function Converter
You can use the fn_converter function to create a converter between two types using closures.
use ;
use Infallible;
use ParseIntError;
// Create a converter between i32 and String using fn_converter
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 Standard Converter
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 using the default StdConverter
let pair = from_left;
assert_eq!;
// Conversion may fail if the value is too large
let pair = from_right;
assert!;