As I can make the vector is mutable
pub struct Test<\'a>{
vec: &\'a mut Vec,
}
impl<\'a> Test<\'a> {
pub fn created
Maybe you are looking for interior mutability. Please, do not use interior mutability loosely, read this first.
use std::cell::RefCell;
pub struct Test{
vec: RefCell>,
}
impl Test {
pub fn created()->Test {
Test {vec: RefCell::new(Vec::new()) }
}
pub fn add(&self, value: i32){
self.vec.borrow_mut().push(value);
}
}
fn main() {
let test = Test::created();
test.add(1i32);
let test1 = Test::created();
// test1 = test; // does not work anymore
}