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>())),
}
}
}