From a23dac3ce01a3cb1e8ae084f591c7925c86b433b Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 23 Feb 2022 21:47:07 +0100 Subject: [PATCH] Rust 2021 - Consts map generated using iterators --- ablescript/Cargo.toml | 2 +- ablescript/src/consts.rs | 12 +++++------- ablescript_cli/Cargo.toml | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ablescript/Cargo.toml b/ablescript/Cargo.toml index 5ed7fd1b..48b5603b 100644 --- a/ablescript/Cargo.toml +++ b/ablescript/Cargo.toml @@ -2,7 +2,7 @@ name = "ablescript" version = "0.2.0" authors = ["able "] -edition = "2018" +edition = "2021" description = "The best programming language" license = "MIT" diff --git a/ablescript/src/consts.rs b/ablescript/src/consts.rs index 3f4c4190..e09b7818 100644 --- a/ablescript/src/consts.rs +++ b/ablescript/src/consts.rs @@ -9,8 +9,7 @@ use crate::variables::{Value, Variable}; pub fn ablescript_consts() -> HashMap { use Value::*; - let mut map = HashMap::new(); - for (name, value) in &[ + [ ("TAU", Int(6)), // Circumference / radius ("PI", Int(3)), // Deprecated, do not use ("EULER", Int(3)), // Mathematical constant e @@ -31,11 +30,10 @@ pub fn ablescript_consts() -> HashMap { ), ("OCTOTHORPE", Str("#".to_owned())), // It's an octothorpe ("ANSWER", Int(ANSWER)), - ] { - map.insert((*name).to_owned(), Variable::from_value(value.to_owned())); - } - - map + ] + .into_iter() + .map(|(name, value)| (name.to_owned(), Variable::from_value(value))) + .collect() } pub const ANSWER: isize = 42; diff --git a/ablescript_cli/Cargo.toml b/ablescript_cli/Cargo.toml index 96a6016b..a423ea78 100644 --- a/ablescript_cli/Cargo.toml +++ b/ablescript_cli/Cargo.toml @@ -2,7 +2,7 @@ name = "ablescript_cli" version = "0.2.0" authors = ["able "] -edition = "2018" +edition = "2021" description = "The best programming language" license = "MIT"