diff --git a/CHANGELOG.md b/CHANGELOG.md index d15153cd..6fa3f6f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ Script-breaking changes * `split` now splits a string by whitespaces instead of splitting it into individual characters. This is more in line with common practices. * A new function `to_chars` for strings is added to split the string into individual characters. +Enhancements +------------ + +* Strings are not directly iterable (via `for .. in`) yielding individual characters. + Version 1.6.0 ============= diff --git a/src/packages/string_basic.rs b/src/packages/string_basic.rs index ae3342ea..c817a24c 100644 --- a/src/packages/string_basic.rs +++ b/src/packages/string_basic.rs @@ -1,5 +1,6 @@ use crate::plugin::*; use crate::{def_package, FnPtr, INT}; +use std::any::TypeId; use std::fmt::{Binary, LowerHex, Octal}; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -20,6 +21,12 @@ def_package! { combine_with_exported_module!(lib, "print_debug", print_debug_functions); combine_with_exported_module!(lib, "number_formatting", number_formatting); + + // Register characters iterator + #[cfg(not(feature = "no_index"))] + lib.set_iter(TypeId::of::(), |value| Box::new( + value.cast::().chars().map(Into::into).collect::().into_iter() + )); } } diff --git a/src/parser.rs b/src/parser.rs index f7e7b9b0..fa665cea 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -316,8 +316,6 @@ impl Expr { #[cfg(not(feature = "no_float"))] Expr::FloatConstant(..) => "a floating-point number", Expr::CharConstant(..) => "a character", - Expr::StringConstant(..) => "a string", - Expr::InterpolatedString(..) => "a string", Expr::Map(..) => "an object map", _ => return Ok(self), };