dynamic_provider/
type_fn.rs

1use core::convert::Infallible;
2
3use crate::{
4    lt::{HktWrapper, LifetimeHkt},
5    Lt,
6};
7
8impl<H: ?Sized> TypeFn for HktWrapper<H>
9where
10    Self: for<'y> LifetimeHkt<Actual<'y>: TypeFn>,
11{
12    type Output<L: Lt> = <L::NextTypeFn<Self> as TypeFn>::Output<L::NextExtending>;
13}
14
15/// Represents a type that is parameterized over one or more lifetime variables.
16///
17/// When a type implementing `TypeFn` is needed, it is usually best to use [`TypeFn!`][trait@TypeFn]
18/// rather than manually implement `TypeFn`.
19///
20/// ## Note
21///
22/// Types implementing this trait are generally meant to be used in generic parameters but not instantiated as values.
23pub trait TypeFn: Sized {
24    type Output<L: Lt>: ?Sized;
25}
26
27impl TypeFn for () {
28    type Output<L: Lt> = Self;
29}
30
31impl TypeFn for Infallible {
32    type Output<L: Lt> = Self;
33}
34
35/// Evaluates to a [`TypeFn`] implementation.
36///
37/// ## Usage
38///
39/// ```ignore
40/// TypeFn![for<'x, 'y, 'z> (Cow<'x, str>, &'y str, &'z mut [u8])]
41/// ```
42#[macro_export]
43macro_rules! TypeFn {
44    (for <> $T:ty) => { $crate::Value<$T> };
45    (for <$lt0:lifetime $(,$lt:lifetime)* $(,)?> $T:ty) => {
46        $crate::LifetimeHkt![for<$lt0> $crate::TypeFn![for <$($lt),*> $T]]
47    };
48    ($T:ty) => { $crate::Value<$T> };
49}