Allow strings to be iterable.

This commit is contained in:
Stephen Chung
2022-04-09 13:37:43 +08:00
parent 6422fddd6d
commit 1777ee7f6f
3 changed files with 12 additions and 2 deletions

View File

@@ -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::<ImmutableString>(), |value| Box::new(
value.cast::<ImmutableString>().chars().map(Into::into).collect::<crate::Array>().into_iter()
));
}
}