future_form 0.3.1

Abstractions over Send and !Send futures
Documentation
use super::*;

trait AltParamTrait<Knd: FutureForm> {
    fn get(&self) -> Knd::Future<'_, u32>;
}

struct AltParamType {
    val: u32,
}

#[future_form(Sendable, Local)]
impl<Knd: FutureForm> AltParamTrait<Knd> for AltParamType {
    fn get(&self) -> Knd::Future<'_, u32> {
        let val = self.val;
        Knd::from_future(async move { val })
    }
}

#[tokio::test]
async fn test_alt_param_sendable() {
    let t = AltParamType { val: 42 };
    let result = <AltParamType as AltParamTrait<Sendable>>::get(&t).await;
    assert_eq!(result, 42);
}

#[tokio::test]
async fn test_alt_param_local() {
    let t = AltParamType { val: 42 };
    let result = <AltParamType as AltParamTrait<Local>>::get(&t).await;
    assert_eq!(result, 42);
}

trait AltParamTrait2<FK: FutureForm> {
    fn get(&self) -> FK::Future<'_, u32>;
}

struct AltParamType2 {
    val: u32,
}

#[future_form(Sendable, Local)]
impl<FK: FutureForm> AltParamTrait2<FK> for AltParamType2 {
    fn get(&self) -> FK::Future<'_, u32> {
        let val = self.val;
        FK::from_future(async move { val })
    }
}

#[tokio::test]
async fn test_alt_param2_sendable() {
    let t = AltParamType2 { val: 42 };
    let result = <AltParamType2 as AltParamTrait2<Sendable>>::get(&t).await;
    assert_eq!(result, 42);
}

#[tokio::test]
async fn test_alt_param2_local() {
    let t = AltParamType2 { val: 42 };
    let result = <AltParamType2 as AltParamTrait2<Local>>::get(&t).await;
    assert_eq!(result, 42);
}