Diffstat (limited to 'src/protocol/walker/hint.rs')
-rw-r--r--src/protocol/walker/hint.rs67
1 files changed, 35 insertions, 32 deletions
diff --git a/src/protocol/walker/hint.rs b/src/protocol/walker/hint.rs
index 1ec93b4..85184de 100644
--- a/src/protocol/walker/hint.rs
+++ b/src/protocol/walker/hint.rs
@@ -4,13 +4,11 @@
//! this module gives a protocol by which a visitor can give a hint
//! to the walker about what it is expecting.
-use core::ops::ControlFlow;
-
use crate::{
- any::{TypeName, TypeNameable},
+ any::{MaybeSized, TypeName},
+ bijective_higher_ranked_type,
effect::{Effect, Future},
hkt::AnySend,
- nameable,
protocol::Visitor,
Flow,
};
@@ -32,45 +30,47 @@ pub trait HintMeta<'ctx> {
pub type Known<'a, 'ctx, Protocol> = AnySend::T<'a, 'ctx, <Protocol as HintMeta<'ctx>>::Known>;
/// Object implementing the [`Hint`] protocol.
-pub trait Hint<'a, 'ctx: 'a, Protocol: ?Sized + HintMeta<'ctx>, E: Effect<'ctx>> {
+pub trait Hint<'ctx, Protocol: ?Sized + HintMeta<'ctx>, E: Effect<'ctx>> {
/// Hint to the walker to use the `P` protocol.
///
/// This should only be called once per [`RequestHint`].
- fn hint(
+ fn hint<'a>(
&'a mut self,
visitor: Visitor<'a, 'ctx>,
hint: <Protocol as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E>;
/// Ask the walker for information about it's support of the protocol.
- fn known(
+ fn known<'a>(
&'a mut self,
hint: &'a <Protocol as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, Protocol>, ()>, E>;
}
-pub type DynHint<'a, 'ctx, Protocol, E> = dyn Hint<'a, 'ctx, Protocol, E> + Send + 'a;
-
-nameable! {
- pub struct Name['ctx, Protocol, E] for<'a>;
-
- impl [Protocol::Name, E] for DynHint<'a, 'ctx, Protocol, E> where {
- Protocol: TypeNameable<'ctx> + ?Sized,
+bijective_higher_ranked_type! {
+ pub type DynHint['ctx][Protocol, E]: MaybeSized['ctx][]
+ for<'a>
+ (dyn Hint<'ctx, Protocol, E> + Send + 'a)
+ where {
E: Effect<'ctx>,
+ Protocol: ?Sized + MaybeSized::Trait<'ctx> + 'ctx,
}
+}
- impl [Protocol, E] where DynHint<'a, 'ctx, Protocol::Nameable, E> {
- Protocol: TypeName<'ctx> + ?Sized,
+bijective_higher_ranked_type! {
+ pub type [][E][Protocol[][]]: TypeName[][]
+ for<'ctx>
+ (DynHint<'ctx, TypeName::T<'ctx, Protocol>, E>)
+ (DynHint<'ctx, Protocol, E>)
+ where {
E: Effect<'ctx>,
+ Protocol: ?Sized,
}
}
#[cfg(test)]
mod test {
- use core::ops::ControlFlow;
-
use crate::{
- any::TypeNameable,
effect::{BlockOn, Blocking, Spin},
higher_ranked_type,
};
@@ -84,24 +84,27 @@ mod test {
#[derive(Debug)]
struct Y;
- nameable! {
- struct Name['a, 'ctx];
- impl for Y where {}
+ bijective_higher_ranked_type! {
+ type DynY['ctx][]: MaybeSized['ctx][] for<'a> (Y)
+ }
+
+ bijective_higher_ranked_type! {
+ type [][]: TypeName[][] for<'ctx> (DynY<'ctx>)
}
- impl<'a, 'ctx: 'a, E: Effect<'ctx>> Hint<'a, 'ctx, Y, E> for X<'ctx> {
- fn hint(
+ impl<'ctx, E: Effect<'ctx>> Hint<'ctx, DynY<'ctx>, E> for X<'ctx> {
+ fn hint<'a>(
&'a mut self,
_visitor: Visitor<'a, 'ctx>,
- _hint: <Y as HintMeta<'ctx>>::Hint,
+ _hint: <DynY<'ctx> as HintMeta<'ctx>>::Hint,
) -> Future<'a, 'ctx, Flow, E> {
todo!()
}
- fn known(
+ fn known<'a>(
&'a mut self,
- _hint: &'a <Y as HintMeta<'ctx>>::Hint,
- ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, Y>, ()>, E> {
+ _hint: &'a <DynY<'ctx> as HintMeta<'ctx>>::Hint,
+ ) -> Future<'a, 'ctx, Result<Known<'a, 'ctx, DynY<'ctx>>, ()>, E> {
E::ready(Ok(&mut *self.0))
}
}
@@ -110,7 +113,7 @@ mod test {
type KnownHkt['ctx]: (AnySend) = for<'lt> &'lt mut i32
}
- impl<'ctx> HintMeta<'ctx> for Y {
+ impl<'ctx> HintMeta<'ctx> for DynY<'ctx> {
type Known = KnownHkt<'ctx>;
type Hint = ();
@@ -118,10 +121,10 @@ mod test {
let mut z = 42;
let mut x = X(&mut z);
- let y: &mut DynHint<'_, '_, Y, Blocking> = &mut x;
+ let y: &mut MaybeSized::T<'_, '_, DynHint<'_, DynY<'_>, Blocking>> = &mut x;
- fn id<'a, 'ctx, T: ?Sized + TypeNameable<'a, 'ctx>>(_x: &T) {}
- id(y);
+ fn id<'a, 'ctx, T: ?Sized + TypeName::Member<'ctx>>(_x: &MaybeSized::T<'a, 'ctx, T>) {}
+ id::<DynHint<'_, DynY<'_>, Blocking>>(y);
let x = Spin::block_on(y.known(&()));
match x {