pub trait Equiv {
type To;
}
Expand description
An Equiv
type is one that is conceptually the same as some
different type.
This is used to allow types to implement typeclasses for other types
in a still strict way. For examples see functor::FunctorSurrogate
, monad::MonadSurrogate
Example - Iterators
In the following example, iter
map
and filter
are all
conceptually “an iterator over usize
”
use std::iter::{Filter, Map};
let vec: Vec<usize> = vec![1, 2, 3, 4, 5];
let iter: std::vec::IntoIter<usize> = vec.into_iter();
let map: Map<std::vec::IntoIter<usize>, _> = iter.map(|n| n + 1);
let filter: Filter<Map<std::vec::IntoIter<usize>, _>, _> = map.filter(|n| n % 2 == 0);
this would imply:
ⓘ
<std::vec::IntoIter<usize> as Equiv>::To == std::vec::IntoIter<usize>
<Map<std::vec::IntoIter<usize>, _> as Equiv>::To == std::vec::IntoIter<usize>
<Filter<Map<std::vec::IntoIter<usize>, _>, _> as Equiv>::To == std::vec::IntoIter<usize>
Other examples:
Result<A, Infallible>
isEquiv::To
Result<A, !>
(and vice versa)IO<Lazy>
isEquiv::To
IO<Lazy::T>
(IO<Suspend<_, usize>>
==IO<usize>
)