1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
//! Testing of the `easy_wrapper!` macro.
#![allow(clippy::multiple_bound_locations)]
use event_listener_strategy::{easy_wrapper, EventListenerFuture, Strategy};
use std::{marker::PhantomData, pin::Pin, task::Poll};
#[cfg(target_family = "wasm")]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[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<&mut Self>,
_strategy: &mut S,
_context: &mut S::Context,
) -> Poll<Self::Output> {
Poll::Ready(())
}
}
easy_wrapper! {
struct MyEasyWrapper(MyStrategy => ());
#[cfg(all(feature = "std", not(target_family = "wasm")))]
wait();
}
#[cfg(all(feature = "std", not(target_family = "wasm")))]
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<&mut Self>,
_strategy: &mut S,
_context: &mut S::Context,
) -> Poll<Self::Output> {
unreachable!()
}
}
easy_wrapper! {
struct MyEasyWrapper2<T>(MyStrategy2<T> => T);
#[cfg(all(feature = "std", not(target_family = "wasm")))]
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<&mut Self>,
_strategy: &mut S,
_context: &mut S::Context,
) -> Poll<Self::Output> {
unreachable!()
}
}
easy_wrapper! {
struct MyEasyWrapperlt<'a>(MyStrategylt<'a> => &'a ());
#[cfg(all(feature = "std", not(target_family = "wasm")))]
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<&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;
#[cfg(all(feature = "std", not(target_family = "wasm")))]
wait();
}
}
|