小编max*_*lun的帖子

错误:闭包要求对“ self”具有唯一的访问权,但“ self”已被借用

我正在学习Rust,并决定实现一个计件表(在本pdf的 6.4节中进行了介绍),因为它非常简单,但并不简单。

这通常是非常简单的,但是我遇到了一个我真的无法弄清楚的问题。这是我的代码的简化版本,以供参考:

use std::ops::Index;

#[derive(Debug)]
pub struct PieceTable {
    // original file data: never changes
    orig_buffer: Vec<u8>,
    // all new data is pushed onto this buffer
    add_buffer: Vec<u8>,
    // the pieces that currently make up the file
    pieces: Vec<Piece>,
}

#[derive(Debug, Copy, Clone)]
enum Location {
    Orig,
    Add,
}

#[derive(Debug, Copy, Clone)]
struct Piece {
    // which buffer is this piece located at?
    buf: Location,
    // starting offset
    start: usize,
    // size of piece
    length: usize,
}

impl …
Run Code Online (Sandbox Code Playgroud)

rust

5
推荐指数
1
解决办法
1420
查看次数

标签 统计

rust ×1