Files
ValueScript/valuescript_vm/src/copy_counter.rs
Andrew Morris 98d1488aff CopyCounter
2023-06-20 11:39:42 +10:00

30 lines
474 B
Rust

use std::{cell::RefCell, rc::Rc};
use crate::vs_value::Val;
#[derive(Debug)]
pub struct CopyCounter {
pub tag: Val,
pub count: Rc<RefCell<usize>>,
}
impl CopyCounter {
pub fn new(tag: Val) -> Self {
CopyCounter {
tag,
count: Rc::new(RefCell::new(0)),
}
}
}
impl Clone for CopyCounter {
fn clone(&self) -> Self {
*self.count.borrow_mut() += 1;
CopyCounter {
tag: self.tag.clone(),
count: self.count.clone(),
}
}
}