Skip to content

Commit

Permalink
Add deprecated methods to ease migration
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile committed Feb 28, 2025
1 parent c596915 commit 0fcee2b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/bevy_ecs/src/query/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,16 @@ impl<D: QueryData, F: QueryFilter> QueryState<D, F> {
self.query(world).single_inner()
}

/// A deprecated alias for [`QueryState::single`].
#[deprecated(since = "0.16.0", note = "Please use `single` instead.")]
#[inline]
pub fn get_single<'w>(
&mut self,
world: &'w World,
) -> Result<ROQueryItem<'w, D>, QuerySingleError> {
self.single(world)
}

/// Returns a single mutable query result when there is exactly one entity matching
/// the query.
///
Expand All @@ -1688,6 +1698,15 @@ impl<D: QueryData, F: QueryFilter> QueryState<D, F> {
self.query_mut(world).single_inner()
}

/// A deprecated alias for [`QueryState::single_mut`].
#[deprecated(since = "0.16.0", note = "Please use `single` instead.")]
pub fn get_single_mut<'w>(
&mut self,
world: &'w mut World,
) -> Result<D::Item<'w>, QuerySingleError> {
self.single_mut(world)
}

/// Returns a query result when there is exactly one entity matching the query.
///
/// If the number of query results is not exactly one, a [`QuerySingleError`] is returned
Expand Down
12 changes: 12 additions & 0 deletions crates/bevy_ecs/src/system/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,12 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
self.as_readonly().single_inner()
}

/// A deprecated alias for [`single`](Self::single).
#[deprecated(since = "0.16", note = "Please use `single` instead")]
pub fn get_single(&self) -> Result<ROQueryItem<'_, D>, QuerySingleError> {
self.single()
}

/// Returns a single query item when there is exactly one entity matching the query.
///
/// If the number of query items is not exactly one, a [`QuerySingleError`] is returned instead.
Expand Down Expand Up @@ -1770,6 +1776,12 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
self.reborrow().single_inner()
}

/// A deprecated alias for [`single_mut`](Self::single_mut).
#[deprecated(since = "0.16", note = "Please use `single_mut` instead")]
pub fn get_single_mut(&mut self) -> Result<D::Item<'_>, QuerySingleError> {
self.single_mut()
}

/// Returns a single query item when there is exactly one entity matching the query.
/// This consumes the [`Query`] to return results with the actual "inner" world lifetime.
///
Expand Down

0 comments on commit 0fcee2b

Please sign in to comment.