Skip to content

Commit

Permalink
rename to get_single
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Sep 10, 2021
1 parent 973b705 commit afe49aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ mod tests {

{
let query = system_state.get(&world);
assert!(query.try_single().is_err());
assert!(query.get_single().is_err());
}

world.entity_mut(entity).get_mut::<A>().unwrap().0 = 2;
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_ecs/src/system/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ where
/// Gets the result of a single-result query.
///
/// Assumes this query has only one result and panics if there are no or multiple results.
/// Use [`Self::try_single`] to handle the error cases explicitly
/// Use [`Self::get_single`] to handle the error cases explicitly
///
/// # Example
///
Expand All @@ -512,7 +512,7 @@ where
where
Q::Fetch: ReadOnlyFetch,
{
self.try_single().unwrap()
self.get_single().unwrap()
}

/// Gets the result of a single-result query.
Expand All @@ -529,7 +529,7 @@ where
/// struct Player;
/// struct Position(f32, f32);
/// fn player_system(query: Query<&Position, With<Player>>) {
/// match query.try_single() {
/// match query.get_single() {
/// Ok(position) => {
/// // do something with position
/// }
Expand All @@ -544,8 +544,8 @@ where
/// # let _check_that_its_a_system = player_system.system();
/// ```
///
/// This can only be called for read-only queries, see [`Self::try_single_mut`] for write-queries.
pub fn try_single(&'s self) -> Result<<Q::Fetch as Fetch<'w, 's>>::Item, QuerySingleError>
/// This can only be called for read-only queries, see [`Self::get_single_mut`] for write-queries.
pub fn get_single(&'s self) -> Result<<Q::Fetch as Fetch<'w, 's>>::Item, QuerySingleError>
where
Q::Fetch: ReadOnlyFetch,
{
Expand All @@ -563,15 +563,15 @@ where
}

/// Gets the query result if it is only a single result, otherwise panics
/// If you want to handle the error case yourself you can use the [`Self::try_single_mut`] variant.
/// If you want to handle the error case yourself you can use the [`Self::get_single_mut`] variant.
#[track_caller]
pub fn single_mut(&mut self) -> <Q::Fetch as Fetch<'_, '_>>::Item {
self.try_single_mut().unwrap()
self.get_single_mut().unwrap()
}

/// Gets the query result if it is only a single result, otherwise returns a
/// [`QuerySingleError`].
pub fn try_single_mut(
pub fn get_single_mut(
&mut self,
) -> Result<<Q::Fetch as Fetch<'_, '_>>::Item, QuerySingleError> {
let mut query = self.iter_mut();
Expand Down

0 comments on commit afe49aa

Please sign in to comment.