-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for generic types to easy_wrapper (#54)
- Loading branch information
Showing
2 changed files
with
182 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//! Testing of the `easy_wrapper!` macro. | ||
use std::{marker::PhantomData, pin::Pin, task::Poll}; | ||
|
||
use event_listener_strategy::{easy_wrapper, EventListenerFuture, Strategy}; | ||
|
||
#[test] | ||
fn easy_wrapper_generics() { | ||
// Easy case. | ||
struct MyStrategy; | ||
|
||
impl EventListenerFuture for MyStrategy { | ||
type Output = (); | ||
|
||
fn poll_with_strategy<'a, S: Strategy<'a>>( | ||
self: Pin<&'a mut Self>, | ||
_strategy: &mut S, | ||
_context: &mut S::Context, | ||
) -> Poll<Self::Output> { | ||
Poll::Ready(()) | ||
} | ||
} | ||
|
||
easy_wrapper! { | ||
struct MyEasyWrapper(MyStrategy => ()); | ||
wait(); | ||
} | ||
|
||
MyEasyWrapper::_new(MyStrategy).wait(); | ||
|
||
// Medium case with generics. | ||
struct MyStrategy2<T> { | ||
_marker: PhantomData<T>, | ||
} | ||
|
||
impl<T> EventListenerFuture for MyStrategy2<T> { | ||
type Output = T; | ||
|
||
fn poll_with_strategy<'a, S: Strategy<'a>>( | ||
self: Pin<&'a mut Self>, | ||
_strategy: &mut S, | ||
_context: &mut S::Context, | ||
) -> Poll<Self::Output> { | ||
unreachable!() | ||
} | ||
} | ||
|
||
easy_wrapper! { | ||
struct MyEasyWrapper2<T>(MyStrategy2<T> => T); | ||
wait(); | ||
} | ||
|
||
// Medium mode with lifetime. | ||
struct MyStrategylt<'a> { | ||
_marker: PhantomData<&'a ()>, | ||
} | ||
|
||
impl<'a> EventListenerFuture for MyStrategylt<'a> { | ||
type Output = &'a (); | ||
|
||
fn poll_with_strategy<'b, S: Strategy<'b>>( | ||
self: Pin<&'b mut Self>, | ||
_strategy: &mut S, | ||
_context: &mut S::Context, | ||
) -> Poll<Self::Output> { | ||
unreachable!() | ||
} | ||
} | ||
|
||
easy_wrapper! { | ||
struct MyEasyWrapperlt<'a>(MyStrategylt<'a> => &'a ()); | ||
wait(); | ||
} | ||
|
||
// Hard mode with generic bounds. | ||
struct MyStrategy3<'a, T: ?Sized> | ||
where | ||
T: 'a, | ||
{ | ||
_marker: PhantomData<&'a T>, | ||
} | ||
|
||
impl<'a, T: ?Sized> EventListenerFuture for MyStrategy3<'a, T> | ||
where | ||
T: 'a, | ||
{ | ||
type Output = &'a T; | ||
|
||
fn poll_with_strategy<'b, S: Strategy<'b>>( | ||
self: Pin<&'b mut Self>, | ||
_strategy: &mut S, | ||
_context: &mut S::Context, | ||
) -> Poll<Self::Output> { | ||
unreachable!() | ||
} | ||
} | ||
|
||
easy_wrapper! { | ||
struct MyEasyWrapper3<'a, T: ?Sized>(MyStrategy3<'a, T> => &'a T) where T: 'a; | ||
wait(); | ||
} | ||
} |