future_form 0.3.1

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

trait AttributeTest<K: FutureForm> {
    fn documented(&self) -> K::Future<'_, u32>;
    fn inline_method(&self) -> K::Future<'_, u32>;
}

struct AttributeType<K> {
    val: u32,
    _marker: PhantomData<K>,
}

#[future_form(Sendable, Local)]
impl<K: FutureForm> AttributeTest<K> for AttributeType<K> {
    /// This method has documentation
    fn documented(&self) -> K::Future<'_, u32> {
        let val = self.val;
        K::from_future(async move { val })
    }

    #[inline]
    fn inline_method(&self) -> K::Future<'_, u32> {
        let val = self.val;
        K::from_future(async move { val + 1 })
    }
}

#[tokio::test]
async fn test_attributes_preserved_sendable() {
    let t: AttributeType<Sendable> = AttributeType {
        val: 42,
        _marker: PhantomData,
    };
    assert_eq!(
        <AttributeType<Sendable> as AttributeTest<Sendable>>::documented(&t).await,
        42
    );
    assert_eq!(
        <AttributeType<Sendable> as AttributeTest<Sendable>>::inline_method(&t).await,
        43
    );
}

#[tokio::test]
async fn test_attributes_preserved_local() {
    let t: AttributeType<Local> = AttributeType {
        val: 42,
        _marker: PhantomData,
    };
    assert_eq!(
        <AttributeType<Local> as AttributeTest<Local>>::documented(&t).await,
        42
    );
    assert_eq!(
        <AttributeType<Local> as AttributeTest<Local>>::inline_method(&t).await,
        43
    );
}