Skip to content

Commit 74c9193

Browse files
committed
add assign as a part of declaration and add tests for it
1 parent 3eda13b commit 74c9193

6 files changed

Lines changed: 545 additions & 126 deletions

File tree

src/env.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::sync::Arc;
2+
use std::collections::HashMap;
3+
4+
#[derive(Debug)]
5+
pub enum Value {
6+
Number(u16),
7+
RGB(u16, u16, u16)
8+
}
9+
10+
#[derive(Debug)]
11+
pub struct Env {
12+
values: HashMap<Arc<str>, Value>
13+
}
14+
15+
impl Env {
16+
pub fn new() -> Self {
17+
let mut vs = Self {
18+
values: HashMap::new()
19+
};
20+
21+
// inner variables
22+
vs.insert("border_color", Value::RGB(176, 176, 176));
23+
vs
24+
}
25+
26+
pub fn insert(&mut self, name: &str, value: Value) {
27+
self.values.insert(name.into(), value);
28+
}
29+
30+
pub fn get(&self, k: &str) -> Option<&Value> {
31+
self.values.get(k.into())
32+
}
33+
}

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use thiserror::Error;
2+
use std::num::ParseIntError;
23

34
#[derive(Error, Debug)]
45
pub enum ParserError{
56
#[error("IO error: {0}")]
67
IOError(#[from] std::io::Error),
78
#[error("{0}")]
89
Err(String),
10+
#[error("IO error: {0}")]
11+
ParseIntError(#[from] ParseIntError),
912
}
1013

1114
#[derive(Error, Debug)]

0 commit comments

Comments
 (0)