我应该如何让 add assign trait 为结构中的向量工作?

问题描述 投票:0回答:0

生锈新手。想了解为什么会出现此问题以及如何解决。我不认为我可以更改 trait 方法实现的签名,这使得它更难修复。

use std::ops::{AddAssign};

pub struct ColumnVector {
    pub data: Vec<f32>
}

impl AddAssign for &ColumnVector {
    fn add_assign(&mut self, other: Self) {
        for (index, elem) in other.data.iter().enumerate() {
            self.data[index] += elem;
        }
    }
}

fn main() {
    
}
rust borrow-checker
© www.soinside.com 2019 - 2024. All rights reserved.