Skip to content

Commit

Permalink
Impl Debug and Default for Groups
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus-consoli committed Mar 24, 2024
1 parent 7850457 commit 397e512
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
24 changes: 17 additions & 7 deletions src/future/future_group.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::fmt;
use core::ops::{Deref, DerefMut};
use core::pin::Pin;
use core::task::{Context, Poll};
Expand Down Expand Up @@ -55,13 +56,28 @@ use crate::collections::inner_group::{InnerGroup, Key, PollFuture};
/// # });}
/// ```
#[must_use = "`FutureGroup` does nothing if not iterated over"]
#[derive(Debug)]
#[pin_project::pin_project]
pub struct FutureGroup<F> {
#[pin]
inner: InnerGroup<F, PollFuture>,
}

impl<F> Default for FutureGroup<F> {
fn default() -> Self {
Self::with_capacity(0)
}
}

impl<T: fmt::Debug> fmt::Debug for FutureGroup<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FutureGroup")
.field("slab", &"[..]")
.field("len", &self.inner.len())
.field("capacity", &self.inner.capacity())
.finish()
}
}

impl<F> FutureGroup<F> {
/// Create a new instance of `FutureGroup`.
///
Expand Down Expand Up @@ -206,12 +222,6 @@ impl<F> FutureGroup<F> {
}
}

impl<F> Default for FutureGroup<F> {
fn default() -> Self {
Self::with_capacity(0)
}
}

impl<F: Future> FutureGroup<F> {
/// Insert a new future into the group.
///
Expand Down
19 changes: 17 additions & 2 deletions src/stream/stream_group.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::fmt::Debug;
use core::fmt;
use core::ops::{Deref, DerefMut};
use core::pin::Pin;
use core::task::{Context, Poll};
Expand Down Expand Up @@ -54,13 +54,28 @@ use crate::collections::inner_group::{InnerGroup, Key, PollStream};
/// # });
/// ```
#[must_use = "`StreamGroup` does nothing if not iterated over"]
#[derive(Default, Debug)]
#[pin_project::pin_project]
pub struct StreamGroup<S> {
#[pin]
inner: InnerGroup<S, PollStream>,
}

impl<F> Default for StreamGroup<F> {
fn default() -> Self {
Self::with_capacity(0)
}
}

impl<T: fmt::Debug> fmt::Debug for StreamGroup<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("StreamGroup")
.field("slab", &"[..]")
.field("len", &self.inner.len())
.field("capacity", &self.inner.capacity())
.finish()
}
}

impl<S> StreamGroup<S> {
/// Create a new instance of `StreamGroup`.
///
Expand Down

0 comments on commit 397e512

Please sign in to comment.