Skip to content

Commit

Permalink
Document bevy_tasks and enable #![warn(missing_docs)] (bevyengine#3509)
Browse files Browse the repository at this point in the history
This PR is part of the issue bevyengine#3492.

# Objective

-  Add and update the bevy_tasks documentation to achieve a 100% documentation coverage (sans `prelude` module)
-  Add the #![warn(missing_docs)] lint to keep the documentation coverage for the future.

## Solution

 -  Add and update the bevy_math documentation.
 -  Add the #![warn(missing_docs)] lint.
 - Added doctest wherever there should be in the missing docs.
  • Loading branch information
james7132 committed Jan 16, 2022
1 parent 71814ca commit e30199f
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 94 deletions.
4 changes: 0 additions & 4 deletions benches/benches/bevy_tasks/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ impl<'a, T> ParallelIterator<std::slice::Iter<'a, T>> for ParChunks<'a, T>
where
T: 'a + Send + Sync,
{
type Item = &'a T;

fn next_batch(&mut self) -> Option<std::slice::Iter<'a, T>> {
self.0.next().map(|s| s.iter())
}
Expand All @@ -18,8 +16,6 @@ impl<'a, T> ParallelIterator<std::slice::IterMut<'a, T>> for ParChunksMut<'a, T>
where
T: 'a + Send + Sync,
{
type Item = &'a mut T;

fn next_batch(&mut self) -> Option<std::slice::IterMut<'a, T>> {
self.0.next().map(|s| s.iter_mut())
}
Expand Down
56 changes: 17 additions & 39 deletions crates/bevy_tasks/src/iter/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ pub struct Chain<T, U> {
impl<B, T, U> ParallelIterator<B> for Chain<T, U>
where
B: Iterator + Send,
T: ParallelIterator<B, Item = B::Item>,
U: ParallelIterator<B, Item = T::Item>,
T: ParallelIterator<B>,
U: ParallelIterator<B>,
{
type Item = T::Item;

fn next_batch(&mut self) -> Option<B> {
if self.left_in_progress {
match self.left.next_batch() {
Expand All @@ -35,11 +33,9 @@ pub struct Map<P, F> {
impl<B, U, T, F> ParallelIterator<std::iter::Map<B, F>> for Map<U, F>
where
B: Iterator + Send,
U: ParallelIterator<B, Item = B::Item>,
F: FnMut(U::Item) -> T + Send + Clone,
U: ParallelIterator<B>,
F: FnMut(B::Item) -> T + Send + Clone,
{
type Item = T;

fn next_batch(&mut self) -> Option<std::iter::Map<B, F>> {
self.iter.next_batch().map(|b| b.map(self.f.clone()))
}
Expand All @@ -54,11 +50,9 @@ pub struct Filter<P, F> {
impl<B, P, F> ParallelIterator<std::iter::Filter<B, F>> for Filter<P, F>
where
B: Iterator + Send,
P: ParallelIterator<B, Item = B::Item>,
F: FnMut(&P::Item) -> bool + Send + Clone,
P: ParallelIterator<B>,
F: FnMut(&B::Item) -> bool + Send + Clone,
{
type Item = P::Item;

fn next_batch(&mut self) -> Option<std::iter::Filter<B, F>> {
self.iter
.next_batch()
Expand All @@ -75,11 +69,9 @@ pub struct FilterMap<P, F> {
impl<B, P, R, F> ParallelIterator<std::iter::FilterMap<B, F>> for FilterMap<P, F>
where
B: Iterator + Send,
P: ParallelIterator<B, Item = B::Item>,
F: FnMut(P::Item) -> Option<R> + Send + Clone,
P: ParallelIterator<B>,
F: FnMut(B::Item) -> Option<R> + Send + Clone,
{
type Item = R;

fn next_batch(&mut self) -> Option<std::iter::FilterMap<B, F>> {
self.iter.next_batch().map(|b| b.filter_map(self.f.clone()))
}
Expand All @@ -94,13 +86,11 @@ pub struct FlatMap<P, F> {
impl<B, P, U, F> ParallelIterator<std::iter::FlatMap<B, U, F>> for FlatMap<P, F>
where
B: Iterator + Send,
P: ParallelIterator<B, Item = B::Item>,
F: FnMut(P::Item) -> U + Send + Clone,
P: ParallelIterator<B>,
F: FnMut(B::Item) -> U + Send + Clone,
U: IntoIterator,
U::IntoIter: Send,
{
type Item = U::Item;

// This extends each batch using the flat map. The other option is
// to turn each IntoIter into its own batch.
fn next_batch(&mut self) -> Option<std::iter::FlatMap<B, U, F>> {
Expand All @@ -116,12 +106,10 @@ pub struct Flatten<P> {
impl<B, P> ParallelIterator<std::iter::Flatten<B>> for Flatten<P>
where
B: Iterator + Send,
P: ParallelIterator<B, Item = B::Item>,
P: ParallelIterator<B>,
B::Item: IntoIterator,
<B::Item as IntoIterator>::IntoIter: Send,
{
type Item = <P::Item as IntoIterator>::Item;

// This extends each batch using the flatten. The other option is to
// turn each IntoIter into its own batch.
fn next_batch(&mut self) -> Option<std::iter::Flatten<B>> {
Expand All @@ -137,10 +125,8 @@ pub struct Fuse<P> {
impl<B, P> ParallelIterator<B> for Fuse<P>
where
B: Iterator + Send,
P: ParallelIterator<B, Item = B::Item>,
P: ParallelIterator<B>,
{
type Item = P::Item;

fn next_batch(&mut self) -> Option<B> {
match &mut self.iter {
Some(iter) => match iter.next_batch() {
Expand All @@ -164,11 +150,9 @@ pub struct Inspect<P, F> {
impl<B, P, F> ParallelIterator<std::iter::Inspect<B, F>> for Inspect<P, F>
where
B: Iterator + Send,
P: ParallelIterator<B, Item = B::Item>,
F: FnMut(&P::Item) + Send + Clone,
P: ParallelIterator<B>,
F: FnMut(&B::Item) + Send + Clone,
{
type Item = P::Item;

fn next_batch(&mut self) -> Option<std::iter::Inspect<B, F>> {
self.iter.next_batch().map(|b| b.inspect(self.f.clone()))
}
Expand All @@ -182,11 +166,9 @@ pub struct Copied<P> {
impl<'a, B, P, T> ParallelIterator<std::iter::Copied<B>> for Copied<P>
where
B: Iterator<Item = &'a T> + Send,
P: ParallelIterator<B, Item = &'a T>,
P: ParallelIterator<B>,
T: 'a + Copy,
{
type Item = T;

fn next_batch(&mut self) -> Option<std::iter::Copied<B>> {
self.iter.next_batch().map(|b| b.copied())
}
Expand All @@ -200,11 +182,9 @@ pub struct Cloned<P> {
impl<'a, B, P, T> ParallelIterator<std::iter::Cloned<B>> for Cloned<P>
where
B: Iterator<Item = &'a T> + Send,
P: ParallelIterator<B, Item = &'a T>,
P: ParallelIterator<B>,
T: 'a + Copy,
{
type Item = T;

fn next_batch(&mut self) -> Option<std::iter::Cloned<B>> {
self.iter.next_batch().map(|b| b.cloned())
}
Expand All @@ -219,10 +199,8 @@ pub struct Cycle<P> {
impl<B, P> ParallelIterator<B> for Cycle<P>
where
B: Iterator + Send,
P: ParallelIterator<B, Item = B::Item> + Clone,
P: ParallelIterator<B> + Clone,
{
type Item = P::Item;

fn next_batch(&mut self) -> Option<B> {
match self.curr.as_mut().and_then(|c| c.next_batch()) {
batch @ Some(_) => batch,
Expand Down
Loading

0 comments on commit e30199f

Please sign in to comment.