unsafe fn try_receive(
        &mut self,
        wait_node: &mut ListNode<RecvWaitQueueEntry>,
        cx: &mut Context<'_>,
    ) -> Poll<Option<T>> {
        match wait_node.state {
            RecvPollState::Unregistered | RecvPollState::Notified => {
                wait_node.state = RecvPollState::Unregistered;

                if !self.buffer.is_empty() {
                    // A value is available - grab it.
                    let val = self.buffer.pop();

                    // Since this means a space in the buffer had been freed,
                    // try to copy a value from a potential waiter into the channel.
                    self.try_copy_value_from_last_waiter();
                    Poll::Ready(Some(val))
                }
                else if !self.send_waiters.is_empty() {
                    // This path should be only used for 0 capacity queues.
                    // Since the list is not empty, a value is available.
                    // Extract it from the sender in order to return it
                    assert_eq!(0, self.buffer.capacity());
                    let last_sender = self.send_waiters.remove_last();
                    assert!(!last_sender.is_null());

                    // Safety: The sender can't be null, since we only add valid
                    // senders to the queue
                    let last_sender = &mut (*last_sender);
                    let val = last_sender.value.take().expect(
                        "Value must be available");
                    last_sender.state = SendPollState::SendComplete;

                    // Wakeup the waiter
                    if let Some(ref task) = &last_sender.task {
                        task.wake_by_ref();
                    }

                    Poll::Ready(Some(val))
                }
                else if self.is_closed {
                    Poll::Ready(None)
                }
                else {
                    // Added the task to the wait queue
                    wait_node.task = Some(cx.waker().clone());
                    wait_node.state = RecvPollState::Registered;
                    self.receive_waiters.add_front(wait_node);
                    Poll::Pending
                }
            },
            RecvPollState::Registered => {
                // Since the channel wakes up all waiters and moves their states
                // to unregistered there can't be any value in the channel in
                // this state.
                Poll::Pending
            },
        }
    }
/// Tries to read the value from the channel.
/// If the value isn't available yet, the ChannelReceiveFuture gets added to the
/// wait queue at the channel, and will be signalled once ready.
/// This function is only safe as long as the `wait_node`s address is guaranteed
/// to be stable until it gets removed from the queue.
Tries to read the value from the channel.
If the value isn't available yet, the ChannelReceiveFuture gets added to the
wait queue at the channel, and will be signalled once ready.
This function is only safe as long as the `wait_node`s address is guaranteed
to be stable until it gets removed from the queue.
Tries to read the value from the channel . If the value isn ' t available yet the ChannelReceiveFuture gets added to the wait queue at the channel and will be signalled once ready . This function is only safe as long as the ` wait_node ` s address is guaranteed to be stable until it gets removed from the queue .
unsafe fn try_receive(
        &mut self,
        wait_node: &mut ListNode<RecvWaitQueueEntry>,
        cx: &mut Context<'_>,
    ) -> Poll<Option<T>> {
        match wait_node.state {
            RecvPollState::Unregistered | RecvPollState::Notified => {
                wait_node.state = RecvPollState::Unregistered;
                if !self.buffer.is_empty() {
                    // A value is available - grab it.
                    let val = self.buffer.pop();
                    // Since this means a space in the buffer had been freed,
                    // try to copy a value from a potential waiter into the channel.
                    self.try_copy_value_from_last_waiter();
                    Poll::Ready(Some(val))
                }
                else if !self.send_waiters.is_empty() {
                    // This path should be only used for 0 capacity queues.
                    // Since the list is not empty, a value is available.
                    // Extract it from the sender in order to return it
                    assert_eq!(0, self.buffer.capacity());
                    let last_sender = self.send_waiters.remove_last();
                    assert!(!last_sender.is_null());
                    // Safety: The sender can't be null, since we only add valid
                    // senders to the queue
                    let last_sender = &mut (*last_sender);
                    let val = last_sender.value.take().expect(
                        "Value must be available");
                    last_sender.state = SendPollState::SendComplete;
                    // Wakeup the waiter
                    if let Some(ref task) = &last_sender.task {
                        task.wake_by_ref();
                    }
                    Poll::Ready(Some(val))
                }
                else if self.is_closed {
                    Poll::Ready(None)
                }
                else {
                    // Added the task to the wait queue
                    wait_node.task = Some(cx.waker().clone());
                    wait_node.state = RecvPollState::Registered;
                    self.receive_waiters.add_front(wait_node);
                    Poll::Pending
                }
            },
            RecvPollState::Registered => {
                // Since the channel wakes up all waiters and moves their states
                // to unregistered there can't be any value in the channel in
                // this state.
                Poll::Pending
            },
        }
    }
unsafe fn try_receive ( & mut self , wait_node : & mut ListNode < RecvWaitQueueEntry > , cx : & mut Context < ' _ > , ) -> Poll < Option < T > > { match wait_node . state { RecvPollState :: Unregistered | RecvPollState :: Notified => { wait_node . state = RecvPollState :: Unregistered ; if ! self . buffer . is_empty ( ) { // A value is available - grab it. let val = self . buffer . pop ( ) ; // Since this means a space in the buffer had been freed, // try to copy a value from a potential waiter into the channel. self . try_copy_value_from_last_waiter ( ) ; Poll :: Ready ( Some ( val ) ) } else if ! self . send_waiters . is_empty ( ) { // This path should be only used for 0 capacity queues. // Since the list is not empty, a value is available. // Extract it from the sender in order to return it assert_eq ! ( 0 self buffer capacity ( ) ) ; let last_sender = self . send_waiters . remove_last ( ) ; assert ! ( last_sender is_null ( ) ) ; // Safety: The sender can't be null, since we only add valid // senders to the queue let last_sender = & mut ( * last_sender ) ; let val = last_sender . value . take ( ) . expect ( " " ) ; last_sender . state = SendPollState :: SendComplete ; // Wakeup the waiter if let Some ( ref task ) = & last_sender . task { task . wake_by_ref ( ) ; } Poll :: Ready ( Some ( val ) ) } else if self . is_closed { Poll :: Ready ( None ) } else { // Added the task to the wait queue wait_node . task = Some ( cx . waker ( ) . clone ( ) ) ; wait_node . state = RecvPollState :: Registered ; self . receive_waiters . add_front ( wait_node ) ; Poll :: Pending } } , RecvPollState :: Registered => { // Since the channel wakes up all waiters and moves their states // to unregistered there can't be any value in the channel in // this state. Poll :: Pending } , } }
Tries to read the value from the channel.
Tries to read the value from the channel .
&mut self
wait_node
&mut ListNode<RecvWaitQueueEntry>
cx
&mut Context<'_>
&mut self
wait_node
&mut ListNode<RecvWaitQueueEntry>
cx
&mut Context<'_>