-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Moved get_component(_unchecked_mut) from Query to QueryState
#9686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alice-i-cecile
merged 18 commits into
bevyengine:main
from
bushrat011899:QueryStateComponentAccess
Sep 11, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
394c506
Moved `get_component(_unchecked_mut)` from `Query` to `QueryState`
ZacHarroldC5 7b3ebb7
Fixed Safety Comment on `get_component_unchecked_mut`
ZacHarroldC5 ed76e87
Merge remote-tracking branch 'upstream/main' into QueryStateComponent…
ZacHarroldC5 dd0a5ea
Formatting Changes
ZacHarroldC5 15f2a61
Method Parity Between `Query` and `QueryState`
ZacHarroldC5 07a580d
Merge remote-tracking branch 'upstream/main' into QueryStateComponent…
ZacHarroldC5 cc476b5
Revert Noisy Changes
ZacHarroldC5 4e16b0b
Fix Missed Revert
ZacHarroldC5 492f209
Reverted Noisy Change
ZacHarroldC5 36bbfa2
Moved `QueryComponentError` and `QueryEntityError` into their own Module
ZacHarroldC5 62eb5d9
Fixed Documentation Links
ZacHarroldC5 fca01f6
Moved `QuerySingleError` into `error.rs`; Added Richer `unwrap` handl…
bushrat011899 87a109a
Merge remote-tracking branch 'upstream/main' into QueryStateComponent…
bushrat011899 3a6c689
Update crates/bevy_ecs/src/query/state.rs
bushrat011899 95ea8c3
Removed `component_unchecked_mut`
bushrat011899 b2f27f4
Follow Up on Consequences
bushrat011899 f3dadd9
Removed Potentially Extraneous `unsafe` `QueryState` Methods
bushrat011899 c9b28cf
Slightly Less Naive Version of This Function
bushrat011899 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| use std::fmt; | ||
|
|
||
| use crate::entity::Entity; | ||
|
|
||
| /// An error that occurs when retrieving a specific [`Entity`]'s query result from [`Query`](crate::system::Query) or [`QueryState`](crate::query::QueryState). | ||
| // TODO: return the type_name as part of this error | ||
| #[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
| pub enum QueryEntityError { | ||
| /// The given [`Entity`]'s components do not match the query. | ||
| /// | ||
| /// Either it does not have a requested component, or it has a component which the query filters out. | ||
| QueryDoesNotMatch(Entity), | ||
| /// The given [`Entity`] does not exist. | ||
| NoSuchEntity(Entity), | ||
| /// The [`Entity`] was requested mutably more than once. | ||
| /// | ||
| /// See [`QueryState::get_many_mut`](crate::query::QueryState::get_many_mut) for an example. | ||
| AliasedMutability(Entity), | ||
| } | ||
|
|
||
| impl std::error::Error for QueryEntityError {} | ||
|
|
||
| impl fmt::Display for QueryEntityError { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| match self { | ||
| QueryEntityError::QueryDoesNotMatch(_) => { | ||
| write!(f, "The given entity's components do not match the query.") | ||
| } | ||
| QueryEntityError::NoSuchEntity(_) => write!(f, "The requested entity does not exist."), | ||
| QueryEntityError::AliasedMutability(_) => { | ||
| write!(f, "The entity was requested mutably more than once.") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// An error that occurs when retrieving a specific [`Entity`]'s component from a [`Query`](crate::system::Query). | ||
| #[derive(Debug, PartialEq, Eq)] | ||
| pub enum QueryComponentError { | ||
| /// The [`Query`](crate::system::Query) does not have read access to the requested component. | ||
| /// | ||
| /// This error occurs when the requested component is not included in the original query. | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ``` | ||
| /// # use bevy_ecs::{prelude::*, query::QueryComponentError}; | ||
| /// # | ||
| /// # #[derive(Component)] | ||
| /// # struct OtherComponent; | ||
| /// # | ||
| /// # #[derive(Component, PartialEq, Debug)] | ||
| /// # struct RequestedComponent; | ||
| /// # | ||
| /// # #[derive(Resource)] | ||
| /// # struct SpecificEntity { | ||
| /// # entity: Entity, | ||
| /// # } | ||
| /// # | ||
| /// fn get_missing_read_access_error(query: Query<&OtherComponent>, res: Res<SpecificEntity>) { | ||
| /// assert_eq!( | ||
| /// query.get_component::<RequestedComponent>(res.entity), | ||
| /// Err(QueryComponentError::MissingReadAccess), | ||
| /// ); | ||
| /// println!("query doesn't have read access to RequestedComponent because it does not appear in Query<&OtherComponent>"); | ||
| /// } | ||
| /// # bevy_ecs::system::assert_is_system(get_missing_read_access_error); | ||
| /// ``` | ||
| MissingReadAccess, | ||
| /// The [`Query`](crate::system::Query) does not have write access to the requested component. | ||
| /// | ||
| /// This error occurs when the requested component is not included in the original query, or the mutability of the requested component is mismatched with the original query. | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ``` | ||
| /// # use bevy_ecs::{prelude::*, query::QueryComponentError}; | ||
| /// # | ||
| /// # #[derive(Component, PartialEq, Debug)] | ||
| /// # struct RequestedComponent; | ||
| /// # | ||
| /// # #[derive(Resource)] | ||
| /// # struct SpecificEntity { | ||
| /// # entity: Entity, | ||
| /// # } | ||
| /// # | ||
| /// fn get_missing_write_access_error(mut query: Query<&RequestedComponent>, res: Res<SpecificEntity>) { | ||
| /// assert_eq!( | ||
| /// query.get_component::<RequestedComponent>(res.entity), | ||
| /// Err(QueryComponentError::MissingWriteAccess), | ||
| /// ); | ||
| /// println!("query doesn't have write access to RequestedComponent because it doesn't have &mut in Query<&RequestedComponent>"); | ||
| /// } | ||
| /// # bevy_ecs::system::assert_is_system(get_missing_write_access_error); | ||
| /// ``` | ||
| MissingWriteAccess, | ||
| /// The given [`Entity`] does not have the requested component. | ||
| MissingComponent, | ||
| /// The requested [`Entity`] does not exist. | ||
| NoSuchEntity, | ||
| } | ||
|
|
||
| impl std::error::Error for QueryComponentError {} | ||
|
|
||
| impl std::fmt::Display for QueryComponentError { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
| match self { | ||
| QueryComponentError::MissingReadAccess => { | ||
| write!( | ||
| f, | ||
| "This query does not have read access to the requested component." | ||
| ) | ||
| } | ||
| QueryComponentError::MissingWriteAccess => { | ||
| write!( | ||
| f, | ||
| "This query does not have write access to the requested component." | ||
| ) | ||
| } | ||
| QueryComponentError::MissingComponent => { | ||
| write!(f, "The given entity does not have the requested component.") | ||
| } | ||
| QueryComponentError::NoSuchEntity => { | ||
| write!(f, "The requested entity does not exist.") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// An error that occurs when evaluating a [`Query`](crate::system::Query) or [`QueryState`](crate::query::QueryState) as a single expected result via | ||
| /// [`get_single`](crate::system::Query::get_single) or [`get_single_mut`](crate::system::Query::get_single_mut). | ||
| #[derive(Debug)] | ||
| pub enum QuerySingleError { | ||
| /// No entity fits the query. | ||
| NoEntities(&'static str), | ||
| /// Multiple entities fit the query. | ||
| MultipleEntities(&'static str), | ||
| } | ||
|
|
||
| impl std::error::Error for QuerySingleError {} | ||
|
|
||
| impl std::fmt::Display for QuerySingleError { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
| match self { | ||
| QuerySingleError::NoEntities(query) => write!(f, "No entities fit the query {query}"), | ||
| QuerySingleError::MultipleEntities(query) => { | ||
| write!(f, "Multiple entities fit the query {query}!") | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.