Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement Debug trait for more types #154

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
any::Any,
ops::Deref,
};
use std::fmt::{Debug, Formatter};
use crate::*;
use futures_core::{stream::{Stream, FusedStream}, future::FusedFuture};
use futures_sink::Sink;
Expand Down Expand Up @@ -141,6 +142,12 @@ pub struct SendFut<'a, T> {
hook: Option<SendState<T>>,
}

impl<'a, T> Debug for SendFut<'a, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("SendFut").finish()
}
}

impl<T> std::marker::Unpin for SendFut<'_, T> {}

impl<'a, T> SendFut<'a, T> {
Expand Down Expand Up @@ -282,6 +289,12 @@ impl<'a, T> SendSink<'a, T> {
}
}

impl<'a, T> Debug for SendSink<'a, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("SendSink").finish()
}
}

impl<'a, T> Sink<T> for SendSink<'a, T> {
type Error = SendError<T>;

Expand Down Expand Up @@ -459,6 +472,12 @@ impl<'a, T> RecvFut<'a, T> {
}
}

impl<'a, T> Debug for RecvFut<'a, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("RecvFut").finish()
}
}

impl<'a, T> Drop for RecvFut<'a, T> {
fn drop(&mut self) {
self.reset_hook();
Expand Down Expand Up @@ -516,6 +535,12 @@ impl<'a, T> RecvStream<'a, T> {
}
}

impl<'a, T> Debug for RecvStream<'a, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("RecvStream").finish()
}
}

impl<'a, T> Clone for RecvStream<'a, T> {
fn clone(&self) -> RecvStream<'a, T> {
RecvStream(RecvFut::new(self.0.receiver.clone()))
Expand Down
26 changes: 25 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use std::{
thread,
fmt,
};

use std::fmt::Formatter;
#[cfg(feature = "spin")]
use spin1::{Mutex as Spinlock, MutexGuard as SpinlockGuard};
use crate::signal::{Signal, SyncSignal};
Expand Down Expand Up @@ -866,6 +866,12 @@ impl<T> WeakSender<T> {
}
}

impl<T> fmt::Debug for WeakSender<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("WeakSender").finish()
}
}

impl<T> Clone for WeakSender<T> {
/// Clones this [`WeakSender`].
fn clone(&self) -> Self {
Expand Down Expand Up @@ -1041,6 +1047,12 @@ pub struct Iter<'a, T> {
receiver: &'a Receiver<T>,
}

impl<'a, T> fmt::Debug for Iter<'a, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Iter").field("receiver", &self.receiver).finish()
}
}

impl<'a, T> Iterator for Iter<'a, T> {
type Item = T;

Expand All @@ -1054,6 +1066,12 @@ pub struct TryIter<'a, T> {
receiver: &'a Receiver<T>,
}

impl<'a, T> fmt::Debug for TryIter<'a, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("TryIter").field("receiver", &self.receiver).finish()
}
}

impl<'a, T> Iterator for TryIter<'a, T> {
type Item = T;

Expand Down Expand Up @@ -1091,6 +1109,12 @@ pub struct IntoIter<T> {
receiver: Receiver<T>,
}

impl<T> fmt::Debug for IntoIter<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("IntoIter").field("receiver", &self.receiver).finish()
}
}

impl<T> Iterator for IntoIter<T> {
type Item = T;

Expand Down
Loading