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

Debug impl of mpsc::error::TrySendError<T> should not bound T: Debug #5664

Closed
GilShoshan94 opened this issue May 1, 2023 · 2 comments · Fixed by #5666
Closed

Debug impl of mpsc::error::TrySendError<T> should not bound T: Debug #5664

GilShoshan94 opened this issue May 1, 2023 · 2 comments · Fixed by #5666
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. E-help-wanted Call for participation: Help is requested to fix this issue. M-sync Module: tokio/sync

Comments

@GilShoshan94
Copy link
Contributor

Hi.

Context

I am writing some kind of generic library code and would like to impose as little as possible bounds to the user.
I am using bounded mpsc channels and and in some place of the code I needed to call try_send(T) and since it has to work there it's the perfect example of where to use an .expect("channel has capacity") to panic in case it doesn't work.

Now, the expect method on Result<T, E> requires E: fmt::Debug, and in this case, E is TrySendError<T> which implement Debug with a derive macro and thus requires my user data to implement Debug on its data type.

Describe the solution you'd like

Manual impl<T> Debug for TrySendError<T> instead of the derive macro that expands to impl<T: Debug> Debug for TrySendError<T>.

Describe alternatives you've considered

When lookin at the std library, on the mpsc channel too, there is also a try_send(T) method and the error, TrySendError<T> implement Debug without any bound on T (see here).

Additional context

It would also be more uniform with the std library API.

Workaround

For now the workaround I am using is try_reserve instead of try_send.
Underneath it is almost the same code except it returns an Ok(Permit) or Err(TrySendError<()>) (and () impl Debug)
So I can use .except(...) on this result, I just the extra step to actually send on the permit, but it doesn't fail ever.

@GilShoshan94 GilShoshan94 added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels May 1, 2023
@Darksonn Darksonn added E-help-wanted Call for participation: Help is requested to fix this issue. M-sync Module: tokio/sync labels May 1, 2023
@Darksonn
Copy link
Contributor

Darksonn commented May 1, 2023

Sure, sounds reasonable enough to me.

@GilShoshan94
Copy link
Contributor Author

Thank you Alice, I will make a PR soon.
I will check also the other channels in comparison with the std lib to have it as uniform as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. E-help-wanted Call for participation: Help is requested to fix this issue. M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants