rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.63k stars 174 forks source link

feat: range indexing on strings #845

Closed zitsen closed 4 months ago

zitsen commented 4 months ago

Now we support range indexing on strings, including ref/mut impls.

For example, you can use range indexing intead of sub_of_string() method like bellow:

let s1 = "abcde";
let s2 = s1[1..4]; // "bcd"
s1[1..4] = "f"; // s1: "afe", s2: "bcd"

Close #841

schungx commented 4 months ago

Wow, I'll look through that.

Probably needs some more tests just to make sure it doesn't muck up indexing a single character ...

Thanks!

zitsen commented 4 months ago

I've test it with cargo test to confirm it wouldn't break anything. For char indexing, I've add a more complex test case to test both char-index and range-index on the same string.

schungx commented 4 months ago

Anyway let's merge this and see how it goes.