my-ecs 0.1.2

An Entity Component System (ECS) library
Documentation
fn main() {
    #[cfg(not(target_arch = "wasm32"))]
    non_web::run();
}

#[cfg(not(target_arch = "wasm32"))]
mod non_web {
    use my_ecs::prelude::*;
    use my_ecs::utils::test_utils::TimerFuture;
    use std::time::Duration;

    pub(super) fn run() {
        // Creates instance.
        let mut ecs = Ecs::create(WorkerPool::with_len(3), [3]);

        // Schedules a future using once system.
        ecs.add_once_system(|rr: ResRead<Post>| rr.send_future(register_map()))
            .unwrap();

        // Waits until all tasks are executed completely.
        ecs.run(|_| {});
    }

    async fn register_map() -> impl Command {
        // Assumes that we're reading map data from a file using async io function.
        TimerFuture::after(Duration::from_millis(10)).await;

        // Now we got the data.
        let map_data = "\
            01000\n\
            01010\n\
            01010\n\
            01010\n\
            00010"
            .to_owned();

        // Declares a command using the data, then returns it.
        let f = move |mut ecs: Ecs| {
            // Registers map resource.
            let map = Map::new(&map_data);
            ecs.add_resource(map)
                .into_result()
                .map_err(EcsError::without_data)?;

            // Appends a system that uses the map.
            ecs.add_once_system(show_map).into_result()?;
            Ok(())
        };
        Ok(f)
    }

    fn show_map(rr: ResRead<Map>) {
        rr.print();
    }

    #[derive(Resource)]
    struct Map(Vec<Vec<char>>);

    impl Map {
        fn new(data: &str) -> Self {
            Self(data.lines().map(|line| line.chars().collect()).collect())
        }

        fn print(&self) {
            for row in self.0.iter() {
                for c in row.iter() {
                    print!("{c}");
                }
                println!();
            }
        }
    }
}