相关疑难解决方法(0)

为什么通过提取方法进行重构会触发借用检查器错误?

我的网络应用程序的体系结构可以简化为以下内容:

use std::collections::HashMap;

/// Represents remote user. Usually has fields,
/// but we omit them for the sake of example.
struct User;

impl User {
    /// Send data to remote user.
    fn send(&mut self, data: &str) {
        println!("Sending data to user: \"{}\"", data);
    }
}

/// A service that handles user data.
/// Usually has non-trivial internal state, but we omit it here.
struct UserHandler {
    users: HashMap<i32, User>,  // Maps user id to User objects.
    counter: i32  // Represents …
Run Code Online (Sandbox Code Playgroud)

rust borrow-checker

4
推荐指数
1
解决办法
122
查看次数

标签 统计

borrow-checker ×1

rust ×1