1use context_interface::LocalContextTr;
3use core::cell::RefCell;
4use std::{rc::Rc, string::String, vec::Vec};
5
6#[derive(Clone, Debug)]
8pub struct LocalContext {
9 pub shared_memory_buffer: Rc<RefCell<Vec<u8>>>,
11 pub precompile_error_message: Option<String>,
13 pub cpsb: u64,
18}
19
20impl Default for LocalContext {
21 fn default() -> Self {
22 Self {
23 shared_memory_buffer: Rc::new(RefCell::new(Vec::with_capacity(1024 * 4))),
24 precompile_error_message: None,
25 cpsb: 0,
26 }
27 }
28}
29
30impl LocalContextTr for LocalContext {
31 fn clear(&mut self) {
32 unsafe { self.shared_memory_buffer.borrow_mut().set_len(0) };
34 self.precompile_error_message = None;
35 self.cpsb = 0;
36 }
37
38 fn shared_memory_buffer(&self) -> &Rc<RefCell<Vec<u8>>> {
39 &self.shared_memory_buffer
40 }
41
42 fn set_precompile_error_context(&mut self, output: String) {
43 self.precompile_error_message = Some(output);
44 }
45
46 fn take_precompile_error_context(&mut self) -> Option<String> {
47 self.precompile_error_message.take()
48 }
49
50 fn cpsb(&self) -> u64 {
51 self.cpsb
52 }
53
54 fn set_cpsb(&mut self, cpsb: u64) {
55 self.cpsb = cpsb;
56 }
57}
58
59impl LocalContext {
60 pub fn new() -> Self {
64 Self::default()
65 }
66}