pub trait InjTypeFn<A: ?Sized>: TypeFn<A, Output = Self::Ret> + RevTypeFn<Self::Ret, Arg = A> {
    type Ret: ?Sized;
}
Expand description

An injective type-level function

This trait is implemented automatically when both TypeFn and RevTypeFn are implemented, and the function is injective. InjTypeFn cannot be manually implemented.

Properties

These are properties about InjTypeFn that users can rely on.

For any given F: InjTypeFn<A> + InjTypeFn<B> these hold:

  1. If A == B, then CallInjFn<F, A> == CallInjFn<F, B>.
  2. If CallInjFn<F, A> == CallInjFn<F, B>, then A == B.
  3. If A != B, then CallInjFn<F, A> != CallInjFn<F, B>.
  4. If CallInjFn<F, A> != CallInjFn<F, B>, then A != B.

Examples

Macro-based Implementation

use typewit::{CallInjFn, UncallFn, inj_type_fn};
 
let _: CallInjFn<BoxFn, u32> = Box::new(3u32);
let _: UncallFn<BoxFn, Box<u32>> = 3u32;
 
inj_type_fn!{
    struct BoxFn;
 
    impl<T: ?Sized> T => Box<T>
}

Non-macro Implementation

use typewit::{CallInjFn, RevTypeFn, TypeFn, UncallFn};
 
let _: CallInjFn<BoxFn, u32> = Box::new(3u32);
let _: UncallFn<BoxFn, Box<u32>> = 3u32;
 
 
struct BoxFn;

impl<T: ?Sized> TypeFn<T> for BoxFn {
    type Output = Box<T>;
 
    // Asserts that this impl of `TypeFn` for `BoxFn` is injective.
    const TYPE_FN_ASSERTS: () = { let _: CallInjFn<Self, T>; };
}
 
impl<T: ?Sized> RevTypeFn<Box<T>> for BoxFn {
    type Arg = T;
}
 

Required Associated Types§

source

type Ret: ?Sized

Return value of the function

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<F, A: ?Sized, R: ?Sized> InjTypeFn<A> for F
where F: TypeFn<A, Output = R> + RevTypeFn<R, Arg = A>,

§

type Ret = R