use std::fmt::Debug;
use std::sync::Arc;
use std::time::Duration;
use futures::StreamExt;
use reactive_mutiny::prelude::advanced::{
GenericUni,
UniZeroCopyAtomic,
Instruments,
};
#[ctor::ctor]
fn suite_setup() {
simple_logger::SimpleLogger::new().with_utc_timestamps().init().unwrap_or_else(|_| eprintln!("--> LOGGER WAS ALREADY STARTED"));
}
#[cfg_attr(not(doc), tokio::test)]
async fn elaborated_generics_on_call_chains() {
const INSTRUMENTS: usize = Instruments::LogsWithExpensiveMetrics.into();
const BUFFER_SIZE: usize = 1024;
type Uni<ItemType> = UniZeroCopyAtomic<ItemType, BUFFER_SIZE, 1, INSTRUMENTS>;
#[allow(dead_code)]
trait CustomTrait<T> { fn get_data(self) -> T; }
#[derive(Debug)]
#[allow(dead_code)]
struct CustomType<T: Debug> {data: T}
impl<T: Debug> CustomTrait<CustomType<T>> for CustomType<T> { fn get_data(self) -> CustomType<T> { CustomType {data: self.data} } }
async fn with_generics<RemoteMessages: CustomTrait<RemoteMessages> + Send + Sync + Debug>
(events_sender: Arc<Uni<RemoteMessages>>,
value: RemoteMessages)
-> bool {
assert!(events_sender.send_with(|slot| *slot = value).is_ok(), "couldn't send value");
events_sender.close(Duration::from_millis(100)).await
}
let uni = Uni::<CustomType<bool>>::new("advanced generics")
.spawn_non_futures_non_fallibles_executors(1,
|remote_messages_stream| remote_messages_stream.map(|_in_msg| CustomType {data: true}),
|_executor| async {});
with_generics(uni, CustomType {data: false}).await;
}