/// Mutate the given target with the given constant value.
Mutate the given target with the given constant value.
Mutate the given target with the given constant value .
pub(crate) fn mut_target(
        &mut self,
        ir_target: &ir::IrTarget,
        op: impl FnOnce(&mut IrValue) -> Result<(), IrError>,
    ) -> Result<(), IrError> {
        match &ir_target.kind {
            ir::IrTargetKind::Name(name) => {
                let value = self.get_name_mut(name.as_ref(), ir_target)?;
                op(value)
            }
            ir::IrTargetKind::Field(target, field) => {
                let current = self.get_target(target)?;
                match current {
                    IrValue::Object(object) => {
                        let mut object = object.borrow_mut().map_err(IrError::access(ir_target))?;
                        let value = object.get_mut(field.as_ref()).ok_or_else(|| {
                            IrError::new(
                                ir_target,
                                IrErrorKind::MissingField {
                                    field: field.clone(),
                                },
                            )
                        })?;
                        op(value)
                    }
                    actual => Err(IrError::expected::<_, runestick::Object>(
                        ir_target, &actual,
                    )),
                }
            }
            ir::IrTargetKind::Index(target, index) => {
                let current = self.get_target(target)?;
                match current {
                    IrValue::Vec(vec) => {
                        let mut vec = vec.borrow_mut().map_err(IrError::access(ir_target))?;
                        let value = vec.get_mut(*index).ok_or_else(|| {
                            IrError::new(ir_target, IrErrorKind::MissingIndex { index: *index })
                        })?;
                        op(value)
                    }
                    IrValue::Tuple(tuple) => {
                        let mut tuple = tuple.borrow_mut().map_err(IrError::access(ir_target))?;
                        let value = tuple.get_mut(*index).ok_or_else(|| {
                            IrError::new(ir_target, IrErrorKind::MissingIndex { index: *index })
                        })?;
                        op(value)
                    }
                    actual => Err(IrError::expected::<_, runestick::Tuple>(ir_target, &actual)),
                }
            }
        }
    }
pub ( crate ) fn mut_target ( & mut self , ir_target : & ir :: IrTarget , op : impl FnOnce ( & mut IrValue ) -> Result < ( ) , IrError > , ) -> Result < ( ) , IrError > { match & ir_target . kind { ir :: IrTargetKind :: Name ( name ) => { let value = self . get_name_mut ( name . as_ref ( ) , ir_target ) ? ; op ( value ) } ir :: IrTargetKind :: Field ( target , field ) => { let current = self . get_target ( target ) ? ; match current { IrValue :: Object ( object ) => { let mut object = object . borrow_mut ( ) . map_err ( IrError :: access ( ir_target ) ) ? ; let value = object . get_mut ( field . as_ref ( ) ) . ok_or_else ( | | { IrError :: new ( ir_target , IrErrorKind :: MissingField { field : field . clone ( ) , } , ) } ) ? ; op ( value ) } actual => Err ( IrError :: expected :: < _ , runestick :: Object > ( ir_target , & actual , ) ) , } } ir :: IrTargetKind :: Index ( target , index ) => { let current = self . get_target ( target ) ? ; match current { IrValue :: Vec ( vec ) => { let mut vec = vec . borrow_mut ( ) . map_err ( IrError :: access ( ir_target ) ) ? ; let value = vec . get_mut ( * index ) . ok_or_else ( | | { IrError :: new ( ir_target , IrErrorKind :: MissingIndex { index : * index } ) } ) ? ; op ( value ) } IrValue :: Tuple ( tuple ) => { let mut tuple = tuple . borrow_mut ( ) . map_err ( IrError :: access ( ir_target ) ) ? ; let value = tuple . get_mut ( * index ) . ok_or_else ( | | { IrError :: new ( ir_target , IrErrorKind :: MissingIndex { index : * index } ) } ) ? ; op ( value ) } actual => Err ( IrError :: expected :: < _ , runestick :: Tuple > ( ir_target , & actual ) ) , } } } }
Mutate the given target with the given constant value.
Mutate the given target with the given constant value .
&mut self
ir_target
&ir::IrTarget
op
impl FnOnce(&mut IrValue) -> Result<(), IrError>