pub(crate) fn eval_op_assignment(
        &self,
        global: &mut GlobalRuntimeState,
        caches: &mut Caches,
        lib: &[&Module],
        op_info: OpAssignment,
        target: &mut Target,
        root: (&str, Position),
        new_val: Dynamic,
        level: usize,
    ) -> RhaiResultOf<()> {
        if target.is_read_only() {
            // Assignment to constant variable
            return Err(ERR::ErrorAssignmentToConstant(root.0.to_string(), root.1).into());
        }

        let mut new_val = new_val;

        if op_info.is_op_assignment() {
            let OpAssignment {
                hash_op_assign,
                hash_op,
                op_assign,
                op,
                pos: op_pos,
            } = op_info;

            let mut lock_guard;
            let lhs_ptr_inner;

            #[cfg(not(feature = "no_closure"))]
            let target_is_shared = target.is_shared();
            #[cfg(feature = "no_closure")]
            let target_is_shared = false;

            if target_is_shared {
                lock_guard = target.write_lock::<Dynamic>().expect("`Dynamic`");
                lhs_ptr_inner = &mut *lock_guard;
            } else {
                lhs_ptr_inner = &mut *target;
            }

            let hash = hash_op_assign;
            let args = &mut [lhs_ptr_inner, &mut new_val];
            let level = level + 1;

            match self.call_native_fn(
                global, caches, lib, op_assign, hash, args, true, true, op_pos, level,
            ) {
                Ok(_) => {
                    #[cfg(not(feature = "unchecked"))]
                    self.check_data_size(&args[0], root.1)?;
                }
                Err(err) if matches!(*err, ERR::ErrorFunctionNotFound(ref f, ..) if f.starts_with(op_assign)) =>
                {
                    // Expand to `var = var op rhs`
                    let (value, ..) = self
                        .call_native_fn(
                            global, caches, lib, op, hash_op, args, true, false, op_pos, level,
                        )
                        .map_err(|err| err.fill_position(op_info.pos))?;

                    #[cfg(not(feature = "unchecked"))]
                    self.check_data_size(&value, root.1)?;

                    *args[0] = value.flatten();
                }
                Err(err) => return Err(err),
            }
        } else {
            // Normal assignment
            *target.as_mut() = new_val;
        }

        target
            .propagate_changed_value()
            .map_err(|err| err.fill_position(op_info.pos))
    }
/// Evaluate an op-assignment statement.
Evaluate an op-assignment statement.
Evaluate an op - assignment statement .
pub(crate) fn eval_op_assignment(
        &self,
        global: &mut GlobalRuntimeState,
        caches: &mut Caches,
        lib: &[&Module],
        op_info: OpAssignment,
        target: &mut Target,
        root: (&str, Position),
        new_val: Dynamic,
        level: usize,
    ) -> RhaiResultOf<()> {
        if target.is_read_only() {
            // Assignment to constant variable
            return Err(ERR::ErrorAssignmentToConstant(root.0.to_string(), root.1).into());
        }
        let mut new_val = new_val;
        if op_info.is_op_assignment() {
            let OpAssignment {
                hash_op_assign,
                hash_op,
                op_assign,
                op,
                pos: op_pos,
            } = op_info;
            let mut lock_guard;
            let lhs_ptr_inner;
            #[cfg(not(feature = "no_closure"))]
            let target_is_shared = target.is_shared();
            #[cfg(feature = "no_closure")]
            let target_is_shared = false;
            if target_is_shared {
                lock_guard = target.write_lock::<Dynamic>().expect("`Dynamic`");
                lhs_ptr_inner = &mut *lock_guard;
            } else {
                lhs_ptr_inner = &mut *target;
            }
            let hash = hash_op_assign;
            let args = &mut [lhs_ptr_inner, &mut new_val];
            let level = level + 1;
            match self.call_native_fn(
                global, caches, lib, op_assign, hash, args, true, true, op_pos, level,
            ) {
                Ok(_) => {
                    #[cfg(not(feature = "unchecked"))]
                    self.check_data_size(&args[0], root.1)?;
                }
                Err(err) if matches!(*err, ERR::ErrorFunctionNotFound(ref f, ..) if f.starts_with(op_assign)) =>
                {
                    // Expand to `var = var op rhs`
                    let (value, ..) = self
                        .call_native_fn(
                            global, caches, lib, op, hash_op, args, true, false, op_pos, level,
                        )
                        .map_err(|err| err.fill_position(op_info.pos))?;
                    #[cfg(not(feature = "unchecked"))]
                    self.check_data_size(&value, root.1)?;
                    *args[0] = value.flatten();
                }
                Err(err) => return Err(err),
            }
        } else {
            // Normal assignment
            *target.as_mut() = new_val;
        }
        target
            .propagate_changed_value()
            .map_err(|err| err.fill_position(op_info.pos))
    }
pub ( crate ) fn eval_op_assignment ( & self , global : & mut GlobalRuntimeState , caches : & mut Caches , lib : & [ & Module ] , op_info : OpAssignment , target : & mut Target , root : ( & str , Position ) , new_val : Dynamic , level : usize , ) -> RhaiResultOf < ( ) > { if target . is_read_only ( ) { // Assignment to constant variable return Err ( ERR :: ErrorAssignmentToConstant ( root . 0 . to_string ( ) , root . 1 ) . into ( ) ) ; } let mut new_val = new_val ; if op_info . is_op_assignment ( ) { let OpAssignment { hash_op_assign , hash_op , op_assign , op , pos : op_pos , } = op_info ; let mut lock_guard ; let lhs_ptr_inner ; # [ cfg ( not ( feature " " ) ) ] let target_is_shared = target . is_shared ( ) ; # [ cfg ( feature " " ) ] let target_is_shared = false ; if target_is_shared { lock_guard = target . write_lock :: < Dynamic > ( ) . expect ( " " ) ; lhs_ptr_inner = & mut * lock_guard ; } else { lhs_ptr_inner = & mut * target ; } let hash = hash_op_assign ; let args = & mut [ lhs_ptr_inner , & mut new_val ] ; let level = level + 1 ; match self . call_native_fn ( global , caches , lib , op_assign , hash , args , true , true , op_pos , level , ) { Ok ( _ ) => { # [ cfg ( not ( feature " " ) ) ] self . check_data_size ( & args [ 0 ] , root . 1 ) ? ; } Err ( err ) if matches ! ( err ERR ErrorFunctionNotFound ( ref f ) if f starts_with ( op_assign ) ) => { // Expand to `var = var op rhs` let ( value , .. ) = self . call_native_fn ( global , caches , lib , op , hash_op , args , true , false , op_pos , level , ) . map_err ( | err | err . fill_position ( op_info . pos ) ) ? ; # [ cfg ( not ( feature " " ) ) ] self . check_data_size ( & value , root . 1 ) ? ; * args [ 0 ] = value . flatten ( ) ; } Err ( err ) => return Err ( err ) , } } else { // Normal assignment * target . as_mut ( ) = new_val ; } target . propagate_changed_value ( ) . map_err ( | err | err . fill_position ( op_info . pos ) ) }
Evaluate an op-assignment statement.
Evaluate an op - assignment statement .
&self
global
&mut GlobalRuntimeState
caches
&mut Caches
lib
&[&Module]
op_info
OpAssignment
target
&mut Target
root
(&str, Position)
new_val
Dynamic
level
usize