Skip to content

Commit

Permalink
Remove the slab dependency
Browse files Browse the repository at this point in the history
Ideally, we should have as few dependencies as possible. This change
inlines most of the logic from `slab` that we used into the
`ListenerSlab` struct.
  • Loading branch information
notgull committed Mar 31, 2023
1 parent 393566a commit 1188962
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 49 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ std = ["parking"]
[dependencies]
crossbeam-utils = { version = "0.8.12", default-features = false }
parking = { version = "2.0.0", optional = true }
slab = { version = "0.4.7", default-features = false }

[dev-dependencies]
waker-fn = "1"
Expand Down
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ use std::time::{Duration, Instant};
use parking::Unparker;

/// An asynchronous waker or thread unparker that can be used to notify a task or thread.
#[derive(Debug)]
enum Task {
/// A waker that can be used to notify a task.
Waker(Waker),
Expand Down Expand Up @@ -122,8 +123,14 @@ impl Task {
}
}

impl PartialEq for Task {
fn eq(&self, other: &Self) -> bool {
self.as_task_ref().will_wake(other.as_task_ref())
}
}

/// A reference to a task.
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
enum TaskRef<'a> {
/// A waker that wakes up a future.
Waker(&'a Waker),
Expand Down Expand Up @@ -749,6 +756,7 @@ impl Drop for EventListener {
}

/// The state of a listener.
#[derive(Debug, PartialEq)]
pub(crate) enum State {
/// It has just been created.
Created,
Expand Down
Loading

0 comments on commit 1188962

Please sign in to comment.