Skip to content

Commit f04c390

Browse files
Doc tests for unhappy paths
1 parent 2423515 commit f04c390

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

crates/bevy_ecs/src/query/state.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ where
164164
///
165165
/// ```rust
166166
/// use bevy_ecs::prelude::*;
167+
/// use bevy_ecs::query::QueryEntityError;
167168
///
168169
/// #[derive(Component, PartialEq, Debug)]
169170
/// struct A(usize);
@@ -183,7 +184,11 @@ where
183184
///
184185
/// let component_values = query_state.get_multiple(&world, entities).unwrap();
185186
///
186-
/// assert_eq!(component_values, [&A(0), &A(1), &A(2)])
187+
/// assert_eq!(component_values, [&A(0), &A(1), &A(2)]);
188+
///
189+
/// let wrong_entity = Entity::from_raw(365);
190+
///
191+
/// assert_eq!(query_state.get_multiple(&world, [wrong_entity]), Err(QueryEntityError::NoSuchEntity(wrong_entity)));
187192
/// ```
188193
#[inline]
189194
pub fn get_multiple<'w, 's, const N: usize>(
@@ -242,6 +247,7 @@ where
242247
///
243248
/// ```rust
244249
/// use bevy_ecs::prelude::*;
250+
/// use bevy_ecs::query::QueryEntityError;
245251
///
246252
/// #[derive(Component, PartialEq, Debug)]
247253
/// struct A(usize);
@@ -267,7 +273,12 @@ where
267273
///
268274
/// let component_values = query_state.get_multiple(&world, entities).unwrap();
269275
///
270-
/// assert_eq!(component_values, [&A(5), &A(6), &A(7)])
276+
/// assert_eq!(component_values, [&A(5), &A(6), &A(7)]);
277+
///
278+
/// let wrong_entity = Entity::from_raw(365);
279+
///
280+
/// assert_eq!(query_state.get_multiple_mut(&mut world, [wrong_entity]), Err(QueryEntityError::NoSuchEntity(wrong_entity)));
281+
/// assert_eq!(query_state.get_multiple_mut(&mut world, [entities[0], entities[0]]), Err(QueryEntityError::AliasedMutability(entities[0])));
271282
/// ```
272283
#[inline]
273284
pub fn get_multiple_mut<'w, 's, const N: usize>(
@@ -870,7 +881,7 @@ where
870881

871882
/// An error that occurs when retrieving a specific [`Entity`]'s query result.
872883
// TODO: return the type_name as part of this error
873-
#[derive(Error, Debug)]
884+
#[derive(Error, Debug, PartialEq, Clone, Copy)]
874885
pub enum QueryEntityError {
875886
#[error("The given entity does not have the requested component.")]
876887
QueryDoesNotMatch,

0 commit comments

Comments
 (0)