async_selector/selector/
id.rs1use std::{
2 fmt, hash,
3 sync::{Arc, Weak},
4};
5
6use crate::list::Node;
7
8#[repr(transparent)]
13pub struct Id<C>(Arc<Node<C>>);
14
15impl<C> Id<C> {
16 pub(super) fn new(node: &Arc<Node<C>>) -> &Self {
17 let ptr = std::ptr::from_ref(node) as *const Self;
18 unsafe { &*ptr }
19 }
20
21 pub(super) fn get(&self) -> &Arc<Node<C>> {
22 &self.0
23 }
24
25 pub fn wake(&self) {
29 self.0.enqueue_by_ref();
30 }
31}
32
33impl<C> Clone for Id<C> {
34 fn clone(&self) -> Self {
35 Self(self.0.clone())
36 }
37}
38
39impl<C> PartialEq for Id<C> {
40 fn eq(&self, other: &Self) -> bool {
41 let this = Arc::as_ptr(&self.0);
42 let other = Arc::as_ptr(&other.0);
43 this.eq(&other)
44 }
45}
46
47impl<C> Eq for Id<C> {}
48
49impl<C> hash::Hash for Id<C> {
50 fn hash<H: hash::Hasher>(&self, state: &mut H) {
51 Arc::as_ptr(&self.0).hash(state);
52 }
53}
54
55impl<C> fmt::Debug for Id<C> {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 f.debug_struct("Id")
58 .field("task_ptr", &Arc::as_ptr(&self.0))
59 .field("queue_ptr", &Weak::as_ptr(self.0.queue()))
60 .finish()
61 }
62}