pub struct SimpleQueryCache { /* private fields */ }Expand description
Cached query for SimpleWorld that avoids re-scanning when the world hasn’t changed.
Tracks a single component type and caches matching entity IDs. Automatically invalidates when the world version changes.
§Example
use cougr_core::query::SimpleQueryCache;
use cougr_core::simple_world::SimpleWorld;
use soroban_sdk::{symbol_short, Bytes, Env};
let env = Env::default();
let mut world = SimpleWorld::new(&env);
let entity = world.spawn_entity();
world.add_component(entity, symbol_short!("position"), Bytes::new(&env));
let mut cache = SimpleQueryCache::new(symbol_short!("position"), &env);
let entities = cache.execute(&world, &env);
assert_eq!(entities.len(), 1);
let entities2 = cache.execute(&world, &env);
assert_eq!(entities2.len(), 1);Implementations§
Source§impl SimpleQueryCache
impl SimpleQueryCache
Sourcepub fn new(component_type: Symbol, env: &Env) -> Self
pub fn new(component_type: Symbol, env: &Env) -> Self
Create a new query cache for a specific component type
Sourcepub fn from_query(query: SimpleQuery, env: &Env) -> Self
pub fn from_query(query: SimpleQuery, env: &Env) -> Self
Create a cache from an explicit SimpleQuery.
Sourcepub fn execute(
&mut self,
world: &SimpleWorld,
env: &Env,
) -> &Vec<SimpleEntityId>
pub fn execute( &mut self, world: &SimpleWorld, env: &Env, ) -> &Vec<SimpleEntityId>
Execute the query, returning cached results if the world hasn’t changed.
Sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
Force invalidation of the cache.
Sourcepub fn is_valid(&self, world_version: u64) -> bool
pub fn is_valid(&self, world_version: u64) -> bool
Check if the cache is up-to-date with the given world version.
Sourcepub fn query(&self) -> &SimpleQuery
pub fn query(&self) -> &SimpleQuery
Returns the underlying query.
Auto Trait Implementations§
impl Freeze for SimpleQueryCache
impl !RefUnwindSafe for SimpleQueryCache
impl !Send for SimpleQueryCache
impl !Sync for SimpleQueryCache
impl Unpin for SimpleQueryCache
impl UnsafeUnpin for SimpleQueryCache
impl !UnwindSafe for SimpleQueryCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W), b: &(T, U, V, W), ) -> Result<Ordering, <C as Compare<(T, U, V, W)>>::Error>
Source§impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W, X), b: &(T, U, V, W, X), ) -> Result<Ordering, <C as Compare<(T, U, V, W, X)>>::Error>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more