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}
14
15impl Default for LocalContext {
16 fn default() -> Self {
17 Self {
18 shared_memory_buffer: Rc::new(RefCell::new(Vec::with_capacity(1024 * 4))),
19 precompile_error_message: None,
20 }
21 }
22}
23
24impl LocalContextTr for LocalContext {
25 fn clear(&mut self) {
26 unsafe { self.shared_memory_buffer.borrow_mut().set_len(0) };
28 self.precompile_error_message = None;
29 }
30
31 fn shared_memory_buffer(&self) -> &Rc<RefCell<Vec<u8>>> {
32 &self.shared_memory_buffer
33 }
34
35 fn set_precompile_error_context(&mut self, output: String) {
36 self.precompile_error_message = Some(output);
37 }
38
39 fn take_precompile_error_context(&mut self) -> Option<String> {
40 self.precompile_error_message.take()
41 }
42}
43
44impl LocalContext {
45 pub fn new() -> Self {
47 Self::default()
48 }
49}