Experiments in applying Entity-Component-System patterns to durable data storage APIs.
1use ecsdb::{query::Without, Component, Ecs, Entity};
2use serde::{Deserialize, Serialize};
3
4pub fn main() -> Result<(), anyhow::Error> {
5 #[derive(Debug, Component, Serialize, Deserialize)]
6 struct Headline(String);
7
8 #[derive(Debug, Component, Serialize, Deserialize)]
9 struct Date(chrono::DateTime<chrono::Utc>);
10
11 let ecs = Ecs::open_in_memory()?;
12 ecs.new_entity()
13 .attach(Headline("My Note".into()))
14 .attach(Date(chrono::Utc::now()));
15
16 ecs.new_entity().attach(Headline("My Note".into()));
17
18 for (entity, headline) in ecs.query::<(Entity, Headline), Without<Date>>() {
19 println!(
20 "Entity '{}' (id={}) is missing component 'Date'",
21 headline.0,
22 entity.id()
23 );
24
25 entity.destroy();
26 }
27
28 Ok(())
29}