Skip to content

Commit 858c7e6

Browse files
committed
Update docs
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 4c087ea commit 858c7e6

File tree

9 files changed

+62
-47
lines changed

9 files changed

+62
-47
lines changed

src/buffer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl Default for RetentionPolicy {
233233
/// To obtain a `BufferKey`, use [`Chain::with_access`][1], or [`listen`][2].
234234
///
235235
/// [1]: crate::Chain::with_access
236-
/// [2]: crate::Bufferable::listen
236+
/// [2]: crate::Accessible::listen
237237
pub struct BufferKey<T> {
238238
tag: BufferKeyTag,
239239
_ignore: std::marker::PhantomData<fn(T)>,

src/buffer/any_buffer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::{
4141
};
4242

4343
/// A [`Buffer`] whose message type has been anonymized. Joining with this buffer
44-
/// type will yield an [`AnyMessage`].
44+
/// type will yield an [`AnyMessageBox`].
4545
#[derive(Clone, Copy)]
4646
pub struct AnyBuffer {
4747
pub(crate) location: BufferLocation,

src/buffer/buffer_map.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,17 @@ impl<T: BufferMapLayout> Buffered for T {
199199
}
200200
}
201201

202-
/// This trait can be implemented for structs that are created by joining a
203-
/// collection of buffers. Usually this
202+
/// This trait can be implemented for structs that are created by joining together
203+
/// values from a collection of buffers. Usually you do not need to implement this
204+
/// yourself. Instead you can use `#[derive(JoinedValue)]`.
204205
pub trait JoinedValue: 'static + Send + Sync + Sized {
205206
/// This associated type must represent a buffer map layout that implements
206207
/// the [`Joined`] trait. The message type yielded by [`Joined`] for this
207208
/// associated type must match the [`JoinedValue`] type.
208209
type Buffers: 'static + BufferMapLayout + Joined<Item = Self> + Send + Sync;
209210

210-
/// Used by [`Builder::join_into`]
211-
fn join_into<'w, 's, 'a, 'b>(
211+
/// Used by [`Self::try_join_from`]
212+
fn join_from<'w, 's, 'a, 'b>(
212213
buffers: Self::Buffers,
213214
builder: &'b mut Builder<'w, 's, 'a>,
214215
) -> Chain<'w, 's, 'a, 'b, Self> {
@@ -226,17 +227,17 @@ pub trait JoinedValue: 'static + Send + Sync + Sized {
226227
Output::new(scope, target).chain(builder)
227228
}
228229

229-
/// Used by [`Builder::try_join_into`]
230-
fn try_join_into<'w, 's, 'a, 'b>(
230+
/// Used by [`Builder::try_join`]
231+
fn try_join_from<'w, 's, 'a, 'b>(
231232
buffers: &BufferMap,
232233
builder: &'b mut Builder<'w, 's, 'a>,
233234
) -> Result<Chain<'w, 's, 'a, 'b, Self>, IncompatibleLayout> {
234235
let buffers: Self::Buffers = Self::Buffers::try_from_buffer_map(buffers)?;
235-
Ok(Self::join_into(buffers, builder))
236+
Ok(Self::join_from(buffers, builder))
236237
}
237238
}
238239

239-
/// Trait to describe a layout of buffer keys
240+
/// Trait to describe a set of buffer keys.
240241
pub trait BufferKeyMap: 'static + Send + Sync + Sized + Clone {
241242
type Buffers: 'static + BufferMapLayout + Accessed<Key = Self> + Send + Sync;
242243
}
@@ -321,6 +322,10 @@ mod tests {
321322
string: String,
322323
}
323324

325+
impl JoinedValue for TestJoinedValue {
326+
type Buffers = TestJoinedValueBuffers;
327+
}
328+
324329
#[derive(Clone)]
325330
struct TestJoinedValueBuffers {
326331
integer: Buffer<i64>,
@@ -378,10 +383,6 @@ mod tests {
378383
}
379384
}
380385

381-
impl JoinedValue for TestJoinedValue {
382-
type Buffers = TestJoinedValueBuffers;
383-
}
384-
385386
#[test]
386387
fn test_try_join() {
387388
let mut context = TestingContext::minimal_plugins();

src/buffer/bufferable.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,29 @@ impl<T: 'static + Send + Sync> Bufferable for Output<T> {
6161
}
6262

6363
pub trait Joinable: Bufferable {
64-
type Item;
64+
type Item: 'static + Send + Sync;
6565

6666
fn join<'w, 's, 'a, 'b>(
6767
self,
6868
builder: &'b mut Builder<'w, 's, 'a>,
6969
) -> Chain<'w, 's, 'a, 'b, Self::Item>;
7070
}
7171

72+
/// This trait is used to create join operations that pull exactly one value
73+
/// from multiple buffers or outputs simultaneously.
7274
impl<B> Joinable for B
7375
where
7476
B: Bufferable,
7577
B::BufferType: Joined,
7678
{
7779
type Item = JoinedItem<B>;
7880

81+
/// Join these bufferable workflow elements. Each time every buffer contains
82+
/// at least one element, this will pull the oldest element from each buffer
83+
/// and join them into a tuple that gets sent to the target.
84+
///
85+
/// If you need a more general way to get access to one or more buffers,
86+
/// use [`listen`](Accessible::listen) instead.
7987
fn join<'w, 's, 'a, 'b>(
8088
self,
8189
builder: &'b mut Builder<'w, 's, 'a>,
@@ -84,9 +92,17 @@ where
8492
}
8593
}
8694

95+
/// This trait is used to create operations that access buffers or outputs.
8796
pub trait Accessible: Bufferable {
88-
type Keys;
97+
type Keys: 'static + Send + Sync;
8998

99+
/// Create an operation that will output buffer access keys each time any
100+
/// one of the buffers is modified. This can be used to create a node in a
101+
/// workflow that wakes up every time one or more buffers change, and then
102+
/// operates on those buffers.
103+
///
104+
/// For an operation that simply joins the contents of two or more outputs
105+
/// or buffers, use [`join`](Joinable::join) instead.
90106
fn listen<'w, 's, 'a, 'b>(
91107
self,
92108
builder: &'b mut Builder<'w, 's, 'a>,

src/buffer/buffered.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub trait Joined: Buffered {
5757
/// and join them into a tuple that gets sent to the target.
5858
///
5959
/// If you need a more general way to get access to one or more buffers,
60-
/// use [`listen`](Self::listen) instead.
60+
/// use [`listen`](Accessed::listen) instead.
6161
fn join<'w, 's, 'a, 'b>(
6262
self,
6363
builder: &'b mut Builder<'w, 's, 'a>,
@@ -90,7 +90,7 @@ pub trait Accessed: Buffered {
9090
/// operates on those buffers.
9191
///
9292
/// For an operation that simply joins the contents of two or more outputs
93-
/// or buffers, use [`join`](Self::join) instead.
93+
/// or buffers, use [`join`](Joined::join) instead.
9494
fn listen<'w, 's, 'a, 'b>(
9595
self,
9696
builder: &'b mut Builder<'w, 's, 'a>,

src/buffer/json_buffer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,10 @@ mod tests {
13671367
json: JsonBuffer,
13681368
}
13691369

1370+
impl JoinedValue for TestJoinedValueJson {
1371+
type Buffers = TestJoinedValueJsonBuffers;
1372+
}
1373+
13701374
impl BufferMapLayout for TestJoinedValueJsonBuffers {
13711375
fn buffer_list(&self) -> smallvec::SmallVec<[AnyBuffer; 8]> {
13721376
use smallvec::smallvec;
@@ -1421,10 +1425,6 @@ mod tests {
14211425
}
14221426
}
14231427

1424-
impl JoinedValue for TestJoinedValueJson {
1425-
type Buffers = TestJoinedValueJsonBuffers;
1426-
}
1427-
14281428
#[test]
14291429
fn test_try_join_json() {
14301430
let mut context = TestingContext::minimal_plugins();

src/builder.rs

+19-21
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ use std::future::Future;
2222
use smallvec::SmallVec;
2323

2424
use crate::{
25-
Accessed, AddOperation, AsMap, Buffer, BufferKeys, BufferLocation, BufferMap, BufferSettings,
25+
Accessed, Accessible, AddOperation, AsMap, Buffer, BufferKeys, BufferLocation, BufferMap, BufferSettings,
2626
Bufferable, Buffered, Chain, Collect, ForkClone, ForkCloneOutput, ForkTargetStorage, Gate,
27-
GateRequest, IncompatibleLayout, Injection, InputSlot, IntoAsyncMap, IntoBlockingMap, Joined,
28-
JoinedItem, JoinedValue, Node, OperateBuffer, OperateBufferAccess, OperateDynamicGate,
27+
GateRequest, IncompatibleLayout, Injection, InputSlot, IntoAsyncMap, IntoBlockingMap, Joinable,
28+
JoinedValue, Node, OperateBuffer, OperateBufferAccess, OperateDynamicGate,
2929
OperateScope, OperateSplit, OperateStaticGate, Output, Provider, RequestOfMap, ResponseOfMap,
3030
Scope, ScopeEndpoints, ScopeSettings, ScopeSettingsStorage, Sendish, Service, SplitOutputs,
3131
Splittable, StreamPack, StreamTargetMap, StreamsOfMap, Trim, TrimBranch, UnusedTarget,
@@ -231,32 +231,28 @@ impl<'w, 's, 'a> Builder<'w, 's, 'a> {
231231
)
232232
}
233233

234-
/// Alternative way of calling [`Bufferable::join`]
235-
pub fn join<'b, B: Bufferable>(&'b mut self, buffers: B) -> Chain<'w, 's, 'a, 'b, JoinedItem<B>>
236-
where
237-
B::BufferType: Joined,
238-
JoinedItem<B>: 'static + Send + Sync,
239-
{
240-
buffers.into_buffer(self).join(self)
234+
/// Alternative way of calling [`Joinable::join`]
235+
pub fn join<'b, B: Joinable>(
236+
&'b mut self,
237+
buffers: B,
238+
) -> Chain<'w, 's, 'a, 'b, B::Item> {
239+
buffers.join(self)
241240
}
242241

243242
/// Try joining a map of buffers into a single value.
244243
pub fn try_join<'b, Joined: JoinedValue>(
245244
&'b mut self,
246245
buffers: &BufferMap,
247246
) -> Result<Chain<'w, 's, 'a, 'b, Joined>, IncompatibleLayout> {
248-
Joined::try_join_into(buffers, self)
247+
Joined::try_join_from(buffers, self)
249248
}
250249

251-
/// Alternative way of calling [`Bufferable::listen`].
252-
pub fn listen<'b, B: Bufferable>(
250+
/// Alternative way of calling [`Accessible::listen`].
251+
pub fn listen<'b, B: Accessible>(
253252
&'b mut self,
254253
buffers: B,
255-
) -> Chain<'w, 's, 'a, 'b, BufferKeys<B>>
256-
where
257-
B::BufferType: Accessed,
258-
{
259-
buffers.into_buffer(self).listen(self)
254+
) -> Chain<'w, 's, 'a, 'b, B::Keys> {
255+
buffers.listen(self)
260256
}
261257

262258
/// Create a node that combines its inputs with access to some buffers. You
@@ -266,11 +262,13 @@ impl<'w, 's, 'a> Builder<'w, 's, 'a> {
266262
///
267263
/// Other [outputs](Output) can also be passed in as buffers. These outputs
268264
/// will be transformed into a buffer with default buffer settings.
269-
pub fn create_buffer_access<T, B>(&mut self, buffers: B) -> Node<T, (T, BufferKeys<B>)>
265+
pub fn create_buffer_access<T, B: Bufferable>(
266+
&mut self,
267+
buffers: B,
268+
) -> Node<T, (T, BufferKeys<B>)>
270269
where
271-
T: 'static + Send + Sync,
272-
B: Bufferable,
273270
B::BufferType: Accessed,
271+
T: 'static + Send + Sync,
274272
{
275273
let buffers = buffers.into_buffer(self);
276274
let source = self.commands.spawn(()).id();

src/chain.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
298298
/// will be transformed into a buffer with default buffer settings.
299299
///
300300
/// To obtain a set of buffer keys each time a buffer is modified, use
301-
/// [`listen`](crate::Bufferable::listen).
301+
/// [`listen`](crate::Accessible::listen).
302302
pub fn with_access<B>(self, buffers: B) -> Chain<'w, 's, 'a, 'b, (T, BufferKeys<B>)>
303303
where
304304
B: Bufferable,
@@ -391,7 +391,7 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
391391
/// The return values of the individual chain builders will be zipped into
392392
/// one tuple return value by this function. If all of the builders return
393393
/// [`Output`] then you can easily continue chaining more operations using
394-
/// [`join`](crate::Bufferable::join), or destructure them into individual
394+
/// [`join`](crate::Joinable::join), or destructure them into individual
395395
/// outputs that you can continue to build with.
396396
pub fn fork_clone<Build: ForkCloneBuilder<T>>(self, build: Build) -> Build::Outputs
397397
where

src/gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ pub enum Gate {
2323
/// receive a wakeup immediately when a gate switches from closed to open,
2424
/// even if none of the data inside the buffer has changed.
2525
///
26-
/// [1]: crate::Bufferable::join
26+
/// [1]: crate::Joinable::join
2727
Open,
2828
/// Close the buffer gate so that listeners (including [join][1] operations)
2929
/// will not be woken up when the data in the buffer gets modified. This
3030
/// effectively blocks the workflow nodes that are downstream of the buffer.
3131
/// Data will build up in the buffer according to its [`BufferSettings`][2].
3232
///
33-
/// [1]: crate::Bufferable::join
33+
/// [1]: crate::Joinable::join
3434
/// [2]: crate::BufferSettings
3535
Closed,
3636
}

0 commit comments

Comments
 (0)