@@ -63,8 +63,7 @@ pub use json_buffer::*;
63
63
/// and release data. When a session is finished, the buffered data from the
64
64
/// session will be automatically cleared.
65
65
pub struct Buffer < T > {
66
- pub ( crate ) scope : Entity ,
67
- pub ( crate ) source : Entity ,
66
+ pub ( crate ) location : BufferLocation ,
68
67
pub ( crate ) _ignore : std:: marker:: PhantomData < fn ( T ) > ,
69
68
}
70
69
@@ -74,11 +73,11 @@ impl<T> Buffer<T> {
74
73
& self ,
75
74
builder : & ' b mut Builder < ' w , ' s , ' a > ,
76
75
) -> Chain < ' w , ' s , ' a , ' b , ( ) > {
77
- assert_eq ! ( self . scope, builder. scope) ;
76
+ assert_eq ! ( self . scope( ) , builder. scope) ;
78
77
let target = builder. commands . spawn ( UnusedTarget ) . id ( ) ;
79
78
builder
80
79
. commands
81
- . add ( OnNewBufferValue :: new ( self . source , target) ) ;
80
+ . add ( OnNewBufferValue :: new ( self . id ( ) , target) ) ;
82
81
Chain :: new ( target, builder)
83
82
}
84
83
@@ -90,15 +89,29 @@ impl<T> Buffer<T> {
90
89
T : Clone ,
91
90
{
92
91
CloneFromBuffer {
93
- scope : self . scope ,
94
- source : self . source ,
92
+ location : self . location ,
95
93
_ignore : Default :: default ( ) ,
96
94
}
97
95
}
98
96
99
97
/// Get an input slot for this buffer.
100
98
pub fn input_slot ( self ) -> InputSlot < T > {
101
- InputSlot :: new ( self . scope , self . source )
99
+ InputSlot :: new ( self . scope ( ) , self . id ( ) )
100
+ }
101
+
102
+ /// Get the entity ID of the buffer.
103
+ pub fn id ( & self ) -> Entity {
104
+ self . location . source
105
+ }
106
+
107
+ /// Get the ID of the workflow that the buffer is associated with.
108
+ pub fn scope ( & self ) -> Entity {
109
+ self . location . scope
110
+ }
111
+
112
+ /// Get general information about the buffer.
113
+ pub fn location ( & self ) -> BufferLocation {
114
+ self . location
102
115
}
103
116
}
104
117
@@ -110,13 +123,40 @@ impl<T> Clone for Buffer<T> {
110
123
111
124
impl < T > Copy for Buffer < T > { }
112
125
126
+ /// Get the general identifying information for a buffer to locate it within the
127
+ /// world. This does not indicate anything about the type of messages that the
128
+ /// buffer can contain.
129
+ #[ derive( Clone , Copy , Debug ) ]
130
+ pub struct BufferLocation {
131
+ /// The entity ID of the buffer.
132
+ pub scope : Entity ,
133
+ /// The ID of the workflow that the buffer is associated with.
134
+ pub source : Entity ,
135
+ }
136
+
113
137
#[ derive( Clone , Copy ) ]
114
138
pub struct CloneFromBuffer < T : Clone > {
115
- pub ( crate ) scope : Entity ,
116
- pub ( crate ) source : Entity ,
139
+ pub ( crate ) location : BufferLocation ,
117
140
pub ( crate ) _ignore : std:: marker:: PhantomData < fn ( T ) > ,
118
141
}
119
142
143
+ impl < T : Clone > CloneFromBuffer < T > {
144
+ /// Get the entity ID of the buffer.
145
+ pub fn id ( & self ) -> Entity {
146
+ self . location . source
147
+ }
148
+
149
+ /// Get the ID of the workflow that the buffer is associated with.
150
+ pub fn scope ( & self ) -> Entity {
151
+ self . location . scope
152
+ }
153
+
154
+ /// Get general information about the buffer.
155
+ pub fn location ( & self ) -> BufferLocation {
156
+ self . location
157
+ }
158
+ }
159
+
120
160
/// Settings to describe the behavior of a buffer.
121
161
#[ derive( Default , Clone , Copy ) ]
122
162
pub struct BufferSettings {
0 commit comments