Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. use std::future::Future;
  2. use std::task::{Context, Poll};
  3. use std::pin::Pin;
  4.  
  5. enum State {
  6. A(i32),
  7. }
  8.  
  9. struct MyFuture {
  10. rx: Pin<Box<dyn Future<Output=i32> + Send>>,
  11. state: State,
  12. }
  13.  
  14. impl Future for MyFuture {
  15. type Output = ();
  16.  
  17. fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
  18. loop {
  19. match &mut self.state {
  20. State::A(n) => {
  21. match Pin::new(&mut self.rx).poll(cx) {
  22. Poll::Ready(_) => {
  23. *n = 10; // 只要有这句就报错
  24. }
  25. _ => unimplemented!(),
  26. }
  27. // *n = 10; // 放这里一样报错
  28. },
  29. }
  30. }
  31. }
  32. }
  33.  
  34. fn main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement