pub fn update_at(
        data: &mut [u8],
        index: usize,
        reference: &Reference,
    ) -> Result<usize, ProgramError> {
        let offset = RefDB::get_offset(data, index)?;
        let mut cur_record = Record::unpack(&data[offset..], reference.get_type(), None)?;
        // update storage counters
        let storage_counter = RefDB::get_storage_counter(data)?;
        if (storage_counter as u32) < u32::MAX {
            RefDB::set_storage_counter(data, storage_counter + 1)?;
        } else {
            RefDB::set_storage_counter(data, 1)?;
        }
        if cur_record.counter == 0 {
            return Err(ProgramError::UninitializedAccount);
        }
        // write record
        if (cur_record.counter as u16) < u16::MAX {
            cur_record.counter += 1;
        } else {
            cur_record.counter = 1;
        }
        cur_record.reference = *reference;
        cur_record.pack(&mut data[offset..])
    }
/// Updates the reference value in the storage at the given index.
/// It doesn't validate storage type, counter or name. Should be used only if
/// record is active (i.e. to update existing record), you are certain that
/// the storage and index are correct, and you don't care if the record was
/// updated since last read time.
Updates the reference value in the storage at the given index.
It doesn't validate storage type, counter or name. Should be used only if
record is active , you are certain that
the storage and index are correct, and you don't care if the record was
updated since last read time.
Updates the reference value in the storage at the given index . It doesn ' t validate storage type counter or name . Should be used only if record is active you are certain that the storage and index are correct and you don ' t care if the record was updated since last read time .
pub fn update_at(
        data: &mut [u8],
        index: usize,
        reference: &Reference,
    ) -> Result<usize, ProgramError> {
        let offset = RefDB::get_offset(data, index)?;
        let mut cur_record = Record::unpack(&data[offset..], reference.get_type(), None)?;
        // update storage counters
        let storage_counter = RefDB::get_storage_counter(data)?;
        if (storage_counter as u32) < u32::MAX {
            RefDB::set_storage_counter(data, storage_counter + 1)?;
        } else {
            RefDB::set_storage_counter(data, 1)?;
        }
        if cur_record.counter == 0 {
            return Err(ProgramError::UninitializedAccount);
        }
        // write record
        if (cur_record.counter as u16) < u16::MAX {
            cur_record.counter += 1;
        } else {
            cur_record.counter = 1;
        }
        cur_record.reference = *reference;
        cur_record.pack(&mut data[offset..])
    }
pub fn update_at ( data : & mut [ u8 ] , index : usize , reference : & Reference , ) -> Result < usize , ProgramError > { let offset = RefDB :: get_offset ( data , index ) ? ; let mut cur_record = Record :: unpack ( & data [ offset .. ] , reference . get_type ( ) , None ) ? ; // update storage counters let storage_counter = RefDB :: get_storage_counter ( data ) ? ; if ( storage_counter as u32 ) < u32 :: MAX { RefDB :: set_storage_counter ( data , storage_counter + 1 ) ? ; } else { RefDB :: set_storage_counter ( data , 1 ) ? ; } if cur_record . counter == 0 { return Err ( ProgramError :: UninitializedAccount ) ; } // write record if ( cur_record . counter as u16 ) < u16 :: MAX { cur_record . counter += 1 ; } else { cur_record . counter = 1 ; } cur_record . reference = * reference ; cur_record . pack ( & mut data [ offset .. ] ) }
Updates the reference value in the storage at the given index.
Updates the reference value in the storage at the given index .
data
&mut [u8]
index
usize
reference
&Reference
data
&mut [u8]
index
usize
reference
&Reference