summaryrefslogtreecommitdiff
path: root/ecs/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-04-06 14:17:30 +0200
committerHampusM <hampus@hampusmat.com>2024-04-06 14:17:30 +0200
commit97f973d685baf389dcde08044dd3dfb7ba556050 (patch)
tree63e67bf212aabd653b5344fd773212e11afd4ae9 /ecs/src
parent407612918489bfa642e2d653edbb54272b3f00f5 (diff)
refactor(ecs): fix Clippy lints
Diffstat (limited to 'ecs/src')
-rw-r--r--ecs/src/actions.rs3
-rw-r--r--ecs/src/event.rs1
-rw-r--r--ecs/src/lib.rs15
-rw-r--r--ecs/src/lock.rs8
4 files changed, 27 insertions, 0 deletions
diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs
index c58b06b..ea4837a 100644
--- a/ecs/src/actions.rs
+++ b/ecs/src/actions.rs
@@ -15,6 +15,9 @@ pub struct Actions<'world>
impl<'world> Actions<'world>
{
/// Adds a spawning a new entity to the action queue.
+ ///
+ /// # Panics
+ /// Will panic if a mutable internal lock cannot be acquired.
pub fn spawn<Comps: ComponentSequence>(&mut self, components: Comps)
{
self.world_data
diff --git a/ecs/src/event.rs b/ecs/src/event.rs
index 01d9d80..9545318 100644
--- a/ecs/src/event.rs
+++ b/ecs/src/event.rs
@@ -19,6 +19,7 @@ pub struct Id
impl Id
{
/// Returns the id of a [`Event`];
+ #[must_use]
pub fn of<EventT: Event>() -> Self
{
Self { inner: TypeId::of::<EventT>() }
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs
index fc97d42..5273b67 100644
--- a/ecs/src/lib.rs
+++ b/ecs/src/lib.rs
@@ -63,6 +63,10 @@ impl World
Self::default()
}
+ /// Creates a new entity with the given components.
+ ///
+ /// # Panics
+ /// Will panic if mutable internal lock cannot be acquired.
pub fn create_entity<Comps>(&mut self, components: Comps)
where
Comps: ComponentSequence,
@@ -122,6 +126,9 @@ impl World
}
/// Peforms the actions that have been queued up using [`Actions`].
+ ///
+ /// # Panics
+ /// Will panic if a mutable internal lock cannot be acquired.
pub fn perform_queued_actions(&self)
{
for action in self
@@ -157,6 +164,10 @@ impl World
}
}
+ /// A event loop which runs until a stop is issued with [`Flags::stop`].
+ ///
+ /// # Panics
+ /// Will panic if a internal lock cannot be acquired.
pub fn event_loop<EventSeq: EventSequence>(&self)
{
let event_seq = EventSeq::ids();
@@ -262,6 +273,7 @@ impl<'world, Comps> Query<'world, Comps>
where
Comps: ComponentSequence,
{
+ #[must_use]
pub fn iter<'this>(&'this self) -> QueryComponentIter<'world, Comps>
where
'this: 'world,
@@ -274,6 +286,7 @@ where
}
/// Returns a weak reference query to the same components.
+ #[must_use]
pub fn to_weak_ref(&self) -> WeakRefQuery<Comps>
{
WeakRefQuery {
@@ -367,6 +380,7 @@ where
/// Returns a struct which can be used to retrieve a [`Query`].
///
/// Returns [`None`] if the [`World`] has been dropped.
+ #[must_use]
pub fn access(&self) -> Option<RefQuery<'_, Comps>>
{
Some(RefQuery {
@@ -404,6 +418,7 @@ impl<'weak_ref, Comps> RefQuery<'weak_ref, Comps>
where
Comps: ComponentSequence,
{
+ #[must_use]
pub fn to_query(&self) -> Query<'_, Comps>
{
Query::new(&self.component_storage)
diff --git a/ecs/src/lock.rs b/ecs/src/lock.rs
index ff46761..c8a8495 100644
--- a/ecs/src/lock.rs
+++ b/ecs/src/lock.rs
@@ -20,6 +20,10 @@ where
Self { inner: RwLock::new(value) }
}
+ /// Tries to a acquire a handle to the resource with read access.
+ ///
+ /// # Errors
+ /// Returns `Err` if unavailable (A mutable handle is hold).
pub fn read_nonblock(&self) -> Result<ReadGuard<Value>, Error>
{
let guard = self.inner.try_read().or_else(|err| match err {
@@ -33,6 +37,10 @@ where
Ok(ReadGuard { inner: guard })
}
+ /// Tries to a acquire a handle to the resource with mutable access.
+ ///
+ /// # Errors
+ /// Returns `Err` if unavailable (A mutable or immutable handle is hold).
pub fn write_nonblock(&self) -> Result<WriteGuard<Value>, Error>
{
let guard = self.inner.try_write().or_else(|err| match err {