Skip to content

Commit

Permalink
fix: add #[non_exhaustive] to TimeoutError
Browse files Browse the repository at this point in the history
It allows removing the private field. This pattern is used for example
by `std::thread::AccessError`.
  • Loading branch information
wyfo committed Jan 7, 2025
1 parent 55cbb16 commit 6efe9ef
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions futures-executor/src/local_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,9 @@ impl ArcWake for ThreadNotify {
}

/// An error returned when a blocking execution times out.
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct TimeoutError {
_private: (),
}

impl TimeoutError {
fn new() -> Self {
Self { _private: () }
}
}

impl fmt::Debug for TimeoutError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("TimeoutError").finish()
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct TimeoutError;

impl fmt::Display for TimeoutError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -152,7 +139,7 @@ fn run_executor_timeout<T, F: FnMut(&mut Context<'_>) -> Poll<T>>(
thread::park_timeout(timeout);
let elapsed = start.elapsed();
if elapsed >= timeout {
return Err(TimeoutError::new());
return Err(TimeoutError);
}
timeout -= elapsed;
Ok(())
Expand Down

0 comments on commit 6efe9ef

Please sign in to comment.