44
55use std:: collections:: VecDeque ;
66
7- /// An object with effects on progress
7+ /// An type containing a number of records accounted for by progress tracking.
88///
99/// The object stores a number of updates and thus is able to describe it count
1010/// (`update_count()`) and whether it is empty (`is_empty()`). It is empty if the
1111/// update count is zero.
12- ///
13- /// It must implement default for historic reason. The default implementation is not required
14- /// to allocate memory for variable-length components.
15- pub trait WithProgress {
12+ pub trait Accountable {
1613 /// The number of records
1714 ///
1815 /// This number is used in progress tracking to confirm the receipt of some number
@@ -22,12 +19,13 @@ pub trait WithProgress {
2219 fn record_count ( & self ) -> i64 ;
2320
2421 /// Determine if this contains any updates, corresponding to `update_count() == 0`.
22+ /// It is a correctness error for this to by anything other than `self.record_count() == 0`.
2523 #[ inline] fn is_empty ( & self ) -> bool { self . record_count ( ) == 0 }
2624}
2725
28- /// A container that allows iteration.
26+ /// A container that allows iteration morally equivalent to [`IntoIterator`] .
2927///
30- /// Iterating the container presents items in an implmentation -specific order.
28+ /// Iterating the container presents items in an implementation -specific order.
3129/// The container's contents are not changed.
3230pub trait IterContainer {
3331 /// The type of elements when reading non-destructively from the container.
@@ -54,7 +52,7 @@ pub trait DrainContainer {
5452}
5553
5654/// A container that can be sized and reveals its capacity.
57- pub trait SizableContainer : Sized {
55+ pub trait SizableContainer {
5856 /// Indicates that the container is "full" and should be shipped.
5957 fn at_capacity ( & self ) -> bool ;
6058 /// Restores `self` to its desired capacity, if it has one.
@@ -65,7 +63,7 @@ pub trait SizableContainer: Sized {
6563 ///
6664 /// Assume that the `stash` is in an undefined state, and properly clear it
6765 /// before re-using it.
68- fn ensure_capacity ( & mut self , stash : & mut Option < Self > ) ;
66+ fn ensure_capacity ( & mut self , stash : & mut Option < Self > ) where Self : Sized ;
6967}
7068
7169/// A container that can absorb items of a specific type.
@@ -90,8 +88,10 @@ pub trait PushInto<T> {
9088///
9189/// The caller should consume the containers returned by [`Self::extract`] and
9290/// [`Self::finish`]. Implementations can recycle buffers, but should ensure that they clear
93- /// any remaining elements. It is up to the implementation of this trait to ensure that
94- /// containers are properly cleared before recycling them.
91+ /// any remaining elements.
92+ ///
93+ /// Implementations are allowed to re-use the contents of the mutable references left by the caller,
94+ /// but they should ensure that they clear the contents before doing so.
9595///
9696/// For example, a consolidating builder can aggregate differences in-place, but it has
9797/// to ensure that it preserves the intended information.
@@ -102,7 +102,7 @@ pub trait ContainerBuilder: Default + 'static {
102102 /// The container type we're building.
103103 // The container is `Clone` because `Tee` requires it, otherwise we need to repeat it
104104 // all over Timely. `'static` because we don't want lifetimes everywhere.
105- type Container : WithProgress + Default + Clone + ' static ;
105+ type Container : Accountable + Default + Clone + ' static ;
106106 /// Extract assembled containers, potentially leaving unfinished data behind. Can
107107 /// be called repeatedly, for example while the caller can send data.
108108 ///
@@ -139,7 +139,7 @@ pub trait ContainerBuilder: Default + 'static {
139139/// A wrapper trait indicating that the container building will preserve the number of records.
140140///
141141/// Specifically, the sum of record counts of all extracted and finished containers must equal the
142- /// number of times that `push_into` is called on the container builder.
142+ /// number of accounted records that are pushed into the container builder.
143143/// If you have any questions about this trait you are best off not implementing it.
144144pub trait LengthPreservingContainerBuilder : ContainerBuilder { }
145145
@@ -175,7 +175,7 @@ impl<T, C: SizableContainer + Default + PushInto<T>> PushInto<T> for CapacityCon
175175 }
176176}
177177
178- impl < C : WithProgress + Default + Clone + ' static > ContainerBuilder for CapacityContainerBuilder < C > {
178+ impl < C : Accountable + Default + Clone + ' static > ContainerBuilder for CapacityContainerBuilder < C > {
179179 type Container = C ;
180180
181181 #[ inline]
@@ -198,9 +198,9 @@ impl<C: WithProgress + Default + Clone + 'static> ContainerBuilder for CapacityC
198198 }
199199}
200200
201- impl < C : WithProgress + SizableContainer + Default + Clone + ' static > LengthPreservingContainerBuilder for CapacityContainerBuilder < C > { }
201+ impl < C : Accountable + SizableContainer + Default + Clone + ' static > LengthPreservingContainerBuilder for CapacityContainerBuilder < C > { }
202202
203- impl < T > WithProgress for Vec < T > {
203+ impl < T > Accountable for Vec < T > {
204204 #[ inline] fn record_count ( & self ) -> i64 { i64:: try_from ( Vec :: len ( self ) ) . unwrap ( ) }
205205 #[ inline] fn is_empty ( & self ) -> bool { Vec :: is_empty ( self ) }
206206}
@@ -263,9 +263,9 @@ mod rc {
263263 use std:: ops:: Deref ;
264264 use std:: rc:: Rc ;
265265
266- use crate :: { WithProgress , IterContainer , DrainContainer } ;
266+ use crate :: { IterContainer , DrainContainer } ;
267267
268- impl < T : WithProgress > WithProgress for Rc < T > {
268+ impl < T : crate :: Accountable > crate :: Accountable for Rc < T > {
269269 #[ inline] fn record_count ( & self ) -> i64 { std:: ops:: Deref :: deref ( self ) . record_count ( ) }
270270 #[ inline] fn is_empty ( & self ) -> bool { std:: ops:: Deref :: deref ( self ) . is_empty ( ) }
271271 }
@@ -285,9 +285,9 @@ mod arc {
285285 use std:: ops:: Deref ;
286286 use std:: sync:: Arc ;
287287
288- use crate :: { WithProgress , IterContainer , DrainContainer } ;
288+ use crate :: { IterContainer , DrainContainer } ;
289289
290- impl < T : WithProgress > WithProgress for Arc < T > {
290+ impl < T : crate :: Accountable > crate :: Accountable for Arc < T > {
291291 #[ inline] fn record_count ( & self ) -> i64 { std:: ops:: Deref :: deref ( self ) . record_count ( ) }
292292 #[ inline] fn is_empty ( & self ) -> bool { std:: ops:: Deref :: deref ( self ) . is_empty ( ) }
293293 }
0 commit comments