async_reciprocals/
lib.rs

1mod api;
2pub use api::*;
3
4#[cfg(test)]
5mod tests {
6    use super::*;
7    use std::error::Error;
8
9    // Define test types for conversion
10    struct Source(String);
11    struct Target(String);
12
13    #[async_trait::async_trait]
14    impl AsyncTryFrom<Source> for Target {
15        type Error = Box<dyn Error + Send + Sync>;
16
17        async fn async_try_from(value: Source) -> Result<Self, Self::Error> {
18            Ok(Target(value.0))
19        }
20    }
21
22    #[tokio::test]
23    async fn test_async_try_from() {
24        // Test AsyncTryFrom trait
25        let source = Source("test data".to_string());
26        let result = Target::async_try_from(source).await;
27        assert!(result.is_ok());
28        assert_eq!(result.unwrap().0, "test data");
29    }
30
31    #[tokio::test]
32    async fn test_async_try_into() {
33        // Test AsyncTryInto trait (should work via blanket implementation)
34        let source = Source("convert me".to_string());
35        let result: Result<Target, _> = source.async_try_into().await;
36        assert!(result.is_ok());
37        assert_eq!(result.unwrap().0, "convert me");
38    }
39
40    #[tokio::test]
41    async fn test_identity_conversion() {
42        // Test the identity conversion (T -> T)
43        let original = "test string".to_string();
44        let result: Result<String, _> = original.clone().async_try_into().await;
45        assert!(result.is_ok());
46        assert_eq!(result.unwrap(), original);
47    }
48
49    // #[test]
50    // fn test_adapter_creation() {
51    //     // Test adapter creation functions from extensions module
52    //     let source = Source("test".to_string());
53
54    //     let _: crate::FromAdapter<Target, Source> =
55    //         extensions::from_to_into(&Target::async_try_from);
56    //     // let _: crate::IntoAdapter<_, Target> =
57    //     //     extensions::into_to_from(&source.async_try_into());
58
59    //     // If we can create these adapters without errors, the test passes
60    // }
61}