1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::any::type_name;
use crate::{Error, Result};
use hecs::{Entity, Query, QueryItem};
pub struct QueryOne<'a, Q: Query> {
entity: Entity,
query: hecs::QueryOne<'a, Q>,
}
impl<'a, Q: Query> QueryOne<'a, Q> {
pub(crate) fn new(entity: Entity, query: hecs::QueryOne<'a, Q>) -> Self {
Self { entity, query }
}
pub fn get(&mut self) -> Result<QueryItem<Q>> {
match self.query.get() {
Some(val) => Ok(val),
None => Err(Error::UnsatisfiedQuery(self.entity, type_name::<Q>())),
}
}
}