use super::*;
trait MethodGeneric<K: FutureForm> {
fn convert<U: ToString + Send + 'static>(&self, u: U) -> K::Future<'_, String>;
}
struct MethodGenericType<K> {
prefix: String,
_marker: PhantomData<K>,
}
#[future_form(Sendable, Local)]
impl<K: FutureForm> MethodGeneric<K> for MethodGenericType<K> {
fn convert<U: ToString + Send + 'static>(&self, u: U) -> K::Future<'_, String> {
let prefix = self.prefix.clone();
K::from_future(async move { format!("{}{}", prefix, u.to_string()) })
}
}
#[tokio::test]
async fn test_method_generic_sendable() {
let t: MethodGenericType<Sendable> = MethodGenericType {
prefix: "value: ".to_string(),
_marker: PhantomData,
};
let result = <MethodGenericType<Sendable> as MethodGeneric<Sendable>>::convert(&t, 42i32).await;
assert_eq!(result, "value: 42");
}
#[tokio::test]
async fn test_method_generic_local() {
let t: MethodGenericType<Local> = MethodGenericType {
prefix: "value: ".to_string(),
_marker: PhantomData,
};
let result = <MethodGenericType<Local> as MethodGeneric<Local>>::convert(&t, 42i32).await;
assert_eq!(result, "value: 42");
}