ready.rs 568 B

12345678910111213141516171819202122232425262728
  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 { self.val.take().unwrap() }
  12. }
  13. impl<T> Unpin for Ready<T> {}
  14. impl<T> Future for Ready<T> {
  15. type Output = T;
  16. #[inline]
  17. fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
  18. let val = self.val.take().expect("Ready polled after completion");
  19. Poll::Ready(val)
  20. }
  21. }
  22. pub fn ready<T>(val: T) -> Ready<T> { Ready { val: Some(val) } }