Skip to content

Commit de6596d

Browse files
committed
Implement more general buffer downcasting
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
1 parent 800a112 commit de6596d

File tree

9 files changed

+339
-136
lines changed

9 files changed

+339
-136
lines changed

.github/workflows/ci_linux.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ jobs:
5050
run: cargo test --features single_threaded_async
5151

5252
- name: Build docs
53-
run: cargo doc
53+
run: cargo doc --all-features
5454

src/buffer.rs

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ pub use json_buffer::*;
6363
/// and release data. When a session is finished, the buffered data from the
6464
/// session will be automatically cleared.
6565
pub struct Buffer<T> {
66-
pub(crate) scope: Entity,
67-
pub(crate) source: Entity,
66+
pub(crate) location: BufferLocation,
6867
pub(crate) _ignore: std::marker::PhantomData<fn(T)>,
6968
}
7069

@@ -74,11 +73,11 @@ impl<T> Buffer<T> {
7473
&self,
7574
builder: &'b mut Builder<'w, 's, 'a>,
7675
) -> Chain<'w, 's, 'a, 'b, ()> {
77-
assert_eq!(self.scope, builder.scope);
76+
assert_eq!(self.scope(), builder.scope);
7877
let target = builder.commands.spawn(UnusedTarget).id();
7978
builder
8079
.commands
81-
.add(OnNewBufferValue::new(self.source, target));
80+
.add(OnNewBufferValue::new(self.id(), target));
8281
Chain::new(target, builder)
8382
}
8483

@@ -90,15 +89,29 @@ impl<T> Buffer<T> {
9089
T: Clone,
9190
{
9291
CloneFromBuffer {
93-
scope: self.scope,
94-
source: self.source,
92+
location: self.location,
9593
_ignore: Default::default(),
9694
}
9795
}
9896

9997
/// Get an input slot for this buffer.
10098
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
102115
}
103116
}
104117

@@ -110,13 +123,40 @@ impl<T> Clone for Buffer<T> {
110123

111124
impl<T> Copy for Buffer<T> {}
112125

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+
113137
#[derive(Clone, Copy)]
114138
pub struct CloneFromBuffer<T: Clone> {
115-
pub(crate) scope: Entity,
116-
pub(crate) source: Entity,
139+
pub(crate) location: BufferLocation,
117140
pub(crate) _ignore: std::marker::PhantomData<fn(T)>,
118141
}
119142

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+
120160
/// Settings to describe the behavior of a buffer.
121161
#[derive(Default, Clone, Copy)]
122162
pub struct BufferSettings {

0 commit comments

Comments
 (0)