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:
- If
A == B
, thenCallInjFn<F, A> == CallInjFn<F, B>
. - If
CallInjFn<F, A> == CallInjFn<F, B>
, thenA == B
. - If
A != B
, thenCallInjFn<F, A> != CallInjFn<F, B>
. - If
CallInjFn<F, A> != CallInjFn<F, B>
, thenA != 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§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.