rust-lang / libs-team

The home of the library team
Apache License 2.0
129 stars 19 forks source link

{,Try}SendError method to get the user data #498

Open SUPERCILEX opened 2 hours ago

SUPERCILEX commented 2 hours ago

Proposal

Problem statement

Not much of a problem, but it's annoying to have to match on the error to get my data back:

match e {
    TrySendError::Full(cmd) => cmd,
    TrySendError::Disconnected(cmd) => cmd,
}

Solution sketch

impl std::sync::mpsc::{,Try}SendError<T> {
  fn into_inner(self) -> T;
}

Alternatives

Write the match every time or write your own helper method.

The into_inner method could be bad in the sense that it obviates the need for the user to think about whether or not they should handle Full vs Disconnected errors differently.

SUPERCILEX commented 2 hours ago

Just realized you can write it like this which is maybe good enough?

let (TrySendError::Full(cmd) | TrySendError::Disconnected(cmd)) = e;