@@ -34,6 +34,7 @@ mod any_buffer;
34
34
pub use any_buffer:: * ;
35
35
36
36
mod buffer_access_lifecycle;
37
+ pub use buffer_access_lifecycle:: BufferKeyLifecycle ;
37
38
pub ( crate ) use buffer_access_lifecycle:: * ;
38
39
39
40
mod buffer_key_builder;
@@ -134,12 +135,15 @@ pub struct BufferLocation {
134
135
pub source : Entity ,
135
136
}
136
137
137
- #[ derive( Clone , Copy ) ]
138
+ #[ derive( Clone ) ]
138
139
pub struct CloneFromBuffer < T : Clone > {
139
140
pub ( crate ) location : BufferLocation ,
140
141
pub ( crate ) _ignore : std:: marker:: PhantomData < fn ( T ) > ,
141
142
}
142
143
144
+ //
145
+ impl < T : Clone > Copy for CloneFromBuffer < T > { }
146
+
143
147
impl < T : Clone > CloneFromBuffer < T > {
144
148
/// Get the entity ID of the buffer.
145
149
pub fn id ( & self ) -> Entity {
@@ -157,6 +161,15 @@ impl<T: Clone> CloneFromBuffer<T> {
157
161
}
158
162
}
159
163
164
+ impl < T : Clone > From < CloneFromBuffer < T > > for Buffer < T > {
165
+ fn from ( value : CloneFromBuffer < T > ) -> Self {
166
+ Buffer {
167
+ location : value. location ,
168
+ _ignore : Default :: default ( ) ,
169
+ }
170
+ }
171
+ }
172
+
160
173
/// Settings to describe the behavior of a buffer.
161
174
#[ derive( Default , Clone , Copy ) ]
162
175
pub struct BufferSettings {
@@ -254,20 +267,23 @@ impl<T> BufferKey<T> {
254
267
pub fn tag ( & self ) -> & BufferKeyTag {
255
268
& self . tag
256
269
}
270
+ }
271
+
272
+ impl < T > BufferKeyLifecycle for BufferKey < T > {
273
+ type TargetBuffer = Buffer < T > ;
274
+
275
+ fn create_key ( buffer : & Self :: TargetBuffer , builder : & BufferKeyBuilder ) -> Self {
276
+ BufferKey {
277
+ tag : builder. make_tag ( buffer. id ( ) ) ,
278
+ _ignore : Default :: default ( ) ,
279
+ }
280
+ }
257
281
258
- pub ( crate ) fn is_in_use ( & self ) -> bool {
282
+ fn is_in_use ( & self ) -> bool {
259
283
self . tag . is_in_use ( )
260
284
}
261
285
262
- // We do a deep clone of the key when distributing it to decouple the
263
- // lifecycle of the keys that we send out from the key that's held by the
264
- // accessor node.
265
- //
266
- // The key instance held by the accessor node will never be dropped until
267
- // the session is cleaned up, so the keys that we send out into the workflow
268
- // need to have their own independent lifecycles or else we won't detect
269
- // when the workflow has dropped them.
270
- pub ( crate ) fn deep_clone ( & self ) -> Self {
286
+ fn deep_clone ( & self ) -> Self {
271
287
Self {
272
288
tag : self . tag . deep_clone ( ) ,
273
289
_ignore : Default :: default ( ) ,
0 commit comments