@@ -34,6 +34,7 @@ mod any_buffer;
3434pub use any_buffer:: * ;
3535
3636mod buffer_access_lifecycle;
37+ pub use buffer_access_lifecycle:: BufferKeyLifecycle ;
3738pub ( crate ) use buffer_access_lifecycle:: * ;
3839
3940mod buffer_key_builder;
@@ -134,12 +135,15 @@ pub struct BufferLocation {
134135 pub source : Entity ,
135136}
136137
137- #[ derive( Clone , Copy ) ]
138+ #[ derive( Clone ) ]
138139pub struct CloneFromBuffer < T : Clone > {
139140 pub ( crate ) location : BufferLocation ,
140141 pub ( crate ) _ignore : std:: marker:: PhantomData < fn ( T ) > ,
141142}
142143
144+ //
145+ impl < T : Clone > Copy for CloneFromBuffer < T > { }
146+
143147impl < T : Clone > CloneFromBuffer < T > {
144148 /// Get the entity ID of the buffer.
145149 pub fn id ( & self ) -> Entity {
@@ -157,6 +161,15 @@ impl<T: Clone> CloneFromBuffer<T> {
157161 }
158162}
159163
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+
160173/// Settings to describe the behavior of a buffer.
161174#[ derive( Default , Clone , Copy ) ]
162175pub struct BufferSettings {
@@ -254,20 +267,23 @@ impl<T> BufferKey<T> {
254267 pub fn tag ( & self ) -> & BufferKeyTag {
255268 & self . tag
256269 }
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+ }
257281
258- pub ( crate ) fn is_in_use ( & self ) -> bool {
282+ fn is_in_use ( & self ) -> bool {
259283 self . tag . is_in_use ( )
260284 }
261285
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 {
271287 Self {
272288 tag : self . tag . deep_clone ( ) ,
273289 _ignore : Default :: default ( ) ,
0 commit comments