stack_vm/table.rs
1//! A simple trait for interacting with various types of table used internally.
2
3/// # Table
4///
5/// A simple trait used for accessing table-like objects.
6///
7/// This trait is used internally for the machine's constant table. As long as
8/// your table type implements this trait then you'll be cool. Meaning you can
9/// choose whatever language semantics you want with regards constants.
10pub trait Table {
11 /// The type for items stored and retrieved from the table.
12 type Item;
13
14 /// Insert a value into the table using a string key.
15 fn insert(&mut self, name: &str, value: Self::Item);
16
17 /// Is the table empty or not?
18 fn is_empty(&self) -> bool;
19
20 /// Does the table contain the key or not?
21 fn contains_key(&self, name: &str) -> bool;
22
23 /// Retrieve a reference to a value stored in the table by key.
24 fn get(&self, name: &str) -> Option<&Self::Item>;
25}