ready.rs 548 B

1234567891011121314151617181920212223242526272829303132
  1. use std::{
  2. future::Future,
  3. pin::Pin,
  4. task::{Context, Poll},
  5. };
  6. pub struct Ready<T> {
  7. val: Option<T>,
  8. }
  9. impl<T> Ready<T> {
  10. #[inline]
  11. pub fn into_inner(mut self) -> T {
  12. self.val.take().unwrap()
  13. }
  14. }
  15. impl<T> Unpin for Ready<T> {}
  16. impl<T> Future for Ready<T> {
  17. type Output = T;
  18. #[inline]
  19. fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
  20. let val = self.val.take().expect("Ready polled after completion");
  21. Poll::Ready(val)
  22. }
  23. }
  24. pub fn ready<T>(val: T) -> Ready<T> {
  25. Ready { val: Some(val) }
  26. }