Debug impl of mpsc::error::TrySendError<T> should not bound T: Debug #5664
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
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 onResult<T, E>
requiresE: fmt::Debug
, and in this case,E
isTrySendError<T>
which implementDebug
with a derive macro and thus requires my user data to implementDebug
on its data type.Describe the solution you'd like
Manual
impl<T> Debug for TrySendError<T>
instead of the derive macro that expands toimpl<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> implementDebug
without any bound onT
(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 oftry_send
.Underneath it is almost the same code except it returns an
Ok(Permit)
orErr(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.The text was updated successfully, but these errors were encountered: