Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use futures::FutureExt;
- use std::future::Future;
- use std::pin::Pin;
- use std::task::{Context, Poll};
- enum State {
- A(i32),
- }
- struct MyFuture {
- rx: Pin<Box<dyn Future<Output = i32> + Send>>,
- state: State,
- }
- /*
- impl Future for MyFuture {
- type Output = ();
- fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
- loop {
- match &mut self.state {
- State::A(n) => {
- match self.rx.poll_unpin(cx) {
- Poll::Ready(_) => {
- }
- _ => unimplemented!(),
- }
- *n = 10; // 只要有这句就报错
- },
- }
- }
- }
- }*/
- fn main() {
- struct A {
- a: i32,
- b: i32,
- }
- let mut a = A { a: 10, b: 10 };
- let b_a = &mut a.a;
- let b_b = &mut a.b;
- *b_b = 30;
- *b_a = 20;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement