Rust 2021

- Consts map generated using iterators
This commit is contained in:
Erin 2022-02-23 21:47:07 +01:00 committed by ondra05
parent d57b692e71
commit a3a0663433
3 changed files with 7 additions and 9 deletions

View file

@ -2,7 +2,7 @@
name = "ablescript" name = "ablescript"
version = "0.2.0" version = "0.2.0"
authors = ["able <abl3theabove@gmail.com>"] authors = ["able <abl3theabove@gmail.com>"]
edition = "2018" edition = "2021"
description = "The best programming language" description = "The best programming language"
license = "MIT" license = "MIT"

View file

@ -9,8 +9,7 @@ use crate::variables::{Value, Variable};
pub fn ablescript_consts() -> HashMap<String, Variable> { pub fn ablescript_consts() -> HashMap<String, Variable> {
use Value::*; use Value::*;
let mut map = HashMap::new(); [
for (name, value) in &[
("TAU", Int(6)), // Circumference / radius ("TAU", Int(6)), // Circumference / radius
("PI", Int(3)), // Deprecated, do not use ("PI", Int(3)), // Deprecated, do not use
("EULER", Int(3)), // Mathematical constant e ("EULER", Int(3)), // Mathematical constant e
@ -31,11 +30,10 @@ pub fn ablescript_consts() -> HashMap<String, Variable> {
), ),
("OCTOTHORPE", Str("#".to_owned())), // It's an octothorpe ("OCTOTHORPE", Str("#".to_owned())), // It's an octothorpe
("ANSWER", Int(ANSWER)), ("ANSWER", Int(ANSWER)),
] { ]
map.insert((*name).to_owned(), Variable::from_value(value.to_owned())); .into_iter()
} .map(|(name, value)| (name.to_owned(), Variable::from_value(value)))
.collect()
map
} }
pub const ANSWER: isize = 42; pub const ANSWER: isize = 42;

View file

@ -2,7 +2,7 @@
name = "ablescript_cli" name = "ablescript_cli"
version = "0.2.0" version = "0.2.0"
authors = ["able <abl3theabove@gmail.com>"] authors = ["able <abl3theabove@gmail.com>"]
edition = "2018" edition = "2021"
description = "The best programming language" description = "The best programming language"
license = "MIT" license = "MIT"