1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- use std::collections::HashMap;
- struct Context {
- variables: Vec<String>,
- var_lookup: HashMap<String, Var>,
- }
- #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
- struct Var {
- idx: usize,
- }
- impl Context {
- fn var(&mut self, name: &str) -> Var {
- if let Some(v) = self.var_lookup.get(name) {
- return *v;
- }
- let idx = self.variables.len();
- let var = Var { idx };
- self.variables.push(name.to_string());
- self.var_lookup.insert(name.to_string(), var);
- var
- }
- }
- impl Var {
- fn show<'r>(&self, ctx: &'r Context) -> &'r str {
- &ctx.variables[self.idx]
- }
- }
- struct StoryState {
- variables: HashMap<Var, Vec<Var>>,
- }
- struct Story {
- state: StoryState,
- storylets: Vec<Storylet>,
- }
- struct Storylet {
- }
- #[cfg(test)]
- mod tests {
- #[test]
- fn it_works() {
- assert_eq!(2 + 2, 4);
- }
- }
|