3 #![feature(generic_associated_types)]
5 use std::marker::PhantomData;
7 pub trait Scalar: 'static {
8 type RefType<'a>: ScalarRef<'a>;
11 pub trait ScalarRef<'a>: 'a {}
14 type RefType<'a> = i32;
17 impl Scalar for String {
18 type RefType<'a> = &'a str;
21 impl Scalar for bool {
22 type RefType<'a> = i32;
25 impl<'a> ScalarRef<'a> for bool {}
27 impl<'a> ScalarRef<'a> for i32 {}
29 impl<'a> ScalarRef<'a> for &'a str {}
31 fn str_contains(a: &str, b: &str) -> bool {
35 pub struct BinaryExpression<A: Scalar, B: Scalar, O: Scalar, F>
37 F: Fn(A::RefType<'_>, B::RefType<'_>) -> O,
40 _phantom: PhantomData<(A, B, O)>,
43 impl<A: Scalar, B: Scalar, O: Scalar, F> BinaryExpression<A, B, O, F>
45 F: Fn(A::RefType<'_>, B::RefType<'_>) -> O,
47 pub fn new(f: F) -> Self {
50 _phantom: PhantomData,
56 BinaryExpression::<String, String, bool, _>::new(str_contains);