How to understand the ownership principle of struct m here?

⚓ Rust    📅 2025-08-01    👤 surdeus    👁️ 10      

surdeus

Warning

This post was published 124 days ago. The information described in this article may have changed.
use anyhow::Result as AnyResult;
#[derive(Debug)]
struct Value(i32);

#[tokio::main]
async fn main() -> AnyResult<()> {
    let mut m = Value(1); 
    async move {
        m.0 = 123;
    }
    .await;
    println!("m: {:?}", m);  //why output: m: Value(1)
    Ok::<_, anyhow::Error>(())
}

Why?

3 posts - 3 participants

Read full topic

🏷️ Rust_feed