use core::convert::Infallible;
use super::{FromFilter, TryFromFilter};
use crate::ScalarFilter;
#[derive(Debug, PartialEq)]
struct Downstream(Option<i64>);
impl FromFilter<ScalarFilter<i64>> for Downstream {
fn from_filter(filter: ScalarFilter<i64>) -> Self {
Self(filter.eq)
}
}
#[test]
fn the_short_half_supplies_the_long_one() {
let filter = ScalarFilter::new().with_eq(7i64);
let crossed = Downstream::try_from_filter(filter).unwrap();
assert_eq!(crossed, Downstream(Some(7)));
}
#[test]
fn a_crossing_that_cannot_fail_says_so_in_its_type() {
fn error_of<C: TryFromFilter<F>, F>(_: &C, _: &F) -> core::marker::PhantomData<C::Error> {
core::marker::PhantomData
}
let filter = ScalarFilter::new().with_eq(7i64);
let crossed = Downstream::try_from_filter(ScalarFilter::new().with_eq(7i64)).unwrap();
let _: core::marker::PhantomData<Infallible> = error_of(&crossed, &filter);
}