ablescript/src/variables.rs

51 lines
917 B
Rust
Raw Normal View History

2021-04-18 16:40:41 -05:00
use rand::Rng;
2021-04-13 18:01:19 -05:00
use std::collections::HashMap;
2021-04-18 16:40:41 -05:00
#[derive(Debug, Clone, PartialEq)]
pub enum Abool {
Never = -1,
Sometimes = 0,
Always = 1,
}
impl Into<bool> for Abool {
fn into(self) -> bool {
match self {
Abool::Never => false,
Abool::Always => true,
Abool::Sometimes => rand::thread_rng().gen(),
}
}
}
2021-04-18 09:39:43 -05:00
#[derive(Debug, Clone)]
pub enum Value {
2021-04-13 18:01:19 -05:00
Str(String),
Int(i32),
Bool(bool),
2021-04-18 16:40:41 -05:00
Abool(Abool),
2021-04-13 18:01:19 -05:00
}
#[derive(Debug)]
pub struct Variable {
melo: bool,
value: Value,
}
pub fn test() {
let mut map = HashMap::new();
let a = Variable {
melo: false,
value: Value::Str("1".to_string()),
};
let b = Variable {
melo: false,
value: Value::Int(2),
};
map.insert("a", a);
map.insert("b", b);
for (key, value) in &map {
println!("{}: {:?}", key, value);
}
}