1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
use crate::{
query::{DefaultQuery, DefaultSendQuery, IntoQuery, IntoSendQuery},
view::{ViewCell, ViewMut, ViewValue},
};
use super::{World, WorldLocal};
impl World {
/// Starts building new view.
///
/// Returned query matches all entities and yields `()` for every one of them.
/// Use [`ViewCell`]'s methods to add sub-queries and filters.
#[inline(always)]
pub fn new_view<'a>(&'a self) -> ViewCell<'a, ()> {
ViewValue::new_cell(self, (), ())
}
/// Starts building new view.
///
/// Borrows world mutably to avoid runtime borrow checks.
///
/// Returned query matches all entities and yields `()` for every one of them.
///
/// Use [`ViewMut`]'s methods to add sub-queries and filters.
#[inline(always)]
pub fn new_view_mut<'a>(&'a mut self) -> ViewMut<'a, ()> {
ViewValue::new(self, (), ())
}
/// Starts building new view.
///
/// Borrows world mutably to avoid runtime borrow checks.
///
/// Returned query matches all entities and yields `()` for every one of them.
///
/// Use [`ViewMut`]'s methods to add sub-queries and filters.
///
/// # Safety
///
/// The caller is responsible that query won't create
/// invalid aliasing of world's components.
#[inline(always)]
pub unsafe fn new_view_unchecked<'a>(&'a mut self) -> ViewMut<'a, ()> {
unsafe { ViewValue::new_unchecked(self, (), ()) }
}
/// Creates new view with single sub-query.
///
/// It requires default-constructible query type.
///
/// Use [`ViewCell`]'s methods to add sub-queries and filters.
#[inline(always)]
pub fn view<'a, Q>(&'a self) -> ViewCell<'a, (Q,)>
where
Q: DefaultSendQuery,
{
ViewValue::new_cell(self, (Q::default_query(),), ())
}
/// Creates new view with single sub-query.
///
/// It requires default-constructible query type.
///
/// Borrows world mutably to avoid runtime borrow checks.
///
/// Use [`ViewMut`]'s methods to add sub-queries and filters.
#[inline(always)]
pub fn view_mut<'a, Q>(&'a mut self) -> ViewMut<'a, (Q,)>
where
Q: DefaultQuery,
{
ViewValue::new(self, (Q::default_query(),), ())
}
/// Creates new view with single sub-query.
///
/// It requires default-constructible query type.
///
/// Borrows world mutably to avoid runtime borrow checks.
///
/// Use [`ViewMut`]'s methods to add sub-queries and filters.
///
/// # Safety
///
/// The caller is responsible that query won't create
/// invalid aliasing of world's components.
#[inline(always)]
pub unsafe fn view_unchecked<'a, Q>(&'a self) -> ViewMut<'a, (Q,)>
where
Q: DefaultQuery,
{
unsafe { ViewValue::new_unchecked(self, (Q::default_query(),), ()) }
}
/// Creates new view with single sub-query.
///
/// Uses provided query instance to support stateful queries.
///
/// Borrows world mutably to avoid runtime borrow checks.
///
/// Use [`ViewCell`]'s methods to add sub-queries and filters.
#[inline(always)]
pub fn view_with<'a, Q>(&'a self, query: Q) -> ViewCell<'a, (Q,)>
where
Q: IntoSendQuery,
{
ViewValue::new_cell(self, (query.into_query(),), ())
}
/// Creates new view with single sub-query.
///
/// Uses provided query instance to support stateful queries.
///
/// Borrows world mutably to avoid runtime borrow checks.
///
/// Use [`ViewMut`]'s methods to add sub-queries and filters.
#[inline(always)]
pub fn view_with_mut<'a, Q>(&'a mut self, query: Q) -> ViewMut<'a, (Q,)>
where
Q: IntoQuery,
{
ViewValue::new(self, (query.into_query(),), ())
}
/// Creates new view with single sub-query.
///
/// Uses provided query instance to support stateful queries.
///
/// Borrows world mutably to avoid runtime borrow checks.
///
/// Use [`ViewMut`]'s methods to add sub-queries and filters.
///
/// # Safety
///
/// The caller is responsible that query won't create
/// invalid aliasing of world's components.
#[inline(always)]
pub unsafe fn view_with_unchecked<'a, Q>(&'a self, query: Q) -> ViewMut<'a, (Q,)>
where
Q: IntoQuery,
{
unsafe { ViewValue::new_unchecked(self, (query.into_query(),), ()) }
}
}
impl WorldLocal {
/// Creates new view with single sub-query.
///
/// It requires default-constructible query type.
///
/// Use [`ViewCell`]'s methods to add sub-queries and filters.
#[inline(always)]
pub fn view<'a, Q>(&'a self) -> ViewCell<'a, (Q,)>
where
Q: DefaultQuery,
{
ViewValue::new_cell(self, (Q::default_query(),), ())
}
/// Creates new view with single sub-query.
///
/// Uses provided query instance to support stateful queries.
///
/// Borrows world mutably to avoid runtime borrow checks.
///
/// Use [`ViewCell`]'s methods to add sub-queries and filters.
#[inline(always)]
pub fn view_with<'a, Q>(&'a self, query: Q) -> ViewCell<'a, (Q,)>
where
Q: IntoQuery,
{
ViewValue::new_cell(self, (query.into_query(),), ())
}
}