Advertisement
Guest User

Untitled

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