-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
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.