Move += for ImmutableString to Engine.

This commit is contained in:
Stephen Chung 2020-05-28 10:33:28 +08:00
parent 854634afa0
commit 0b259d0062
2 changed files with 9 additions and 6 deletions

View File

@ -18,10 +18,7 @@ use crate::utils::StaticVec;
use crate::parser::FLOAT;
#[cfg(not(feature = "no_module"))]
use crate::module::{resolvers, ModuleRef, ModuleResolver};
#[cfg(feature = "no_module")]
use crate::parser::ModuleRef;
use crate::module::{resolvers, ModuleResolver};
use crate::stdlib::{
any::TypeId,
@ -30,7 +27,6 @@ use crate::stdlib::{
format,
iter::{empty, once},
mem,
num::NonZeroUsize,
ops::{Deref, DerefMut},
string::{String, ToString},
vec::Vec,
@ -2186,6 +2182,14 @@ fn run_builtin_op_assignment(
"|=" => return Ok(Some(*x = *x || y)),
_ => (),
}
} else if args_type == TypeId::of::<ImmutableString>() {
let x = x.downcast_mut::<ImmutableString>().unwrap();
let y = y.downcast_ref::<ImmutableString>().unwrap();
match op {
"+=" => return Ok(Some(*x += y)),
_ => (),
}
}
#[cfg(not(feature = "no_float"))]

View File

@ -81,6 +81,5 @@ def_package!(crate:BasicStringPackage:"Basic string utilities, including printin
lib.set_fn_2("+", |s: ImmutableString, ch: char| Ok(s + ch));
lib.set_fn_2_mut("+=", |s: &mut ImmutableString, ch: char| { *s += ch; Ok(()) });
lib.set_fn_2_mut("append", |s: &mut ImmutableString, ch: char| { *s += ch; Ok(()) });
lib.set_fn_2_mut("+=", |s: &mut ImmutableString, s2: ImmutableString| { *s += &s2; Ok(()) });
lib.set_fn_2_mut("append", |s: &mut ImmutableString, s2: ImmutableString| { *s += &s2; Ok(()) });
});