pub fn delete(data: &mut [u8], record: &Record) -> Result<usize, ProgramError> {
        let offset = if let Some(idx) = record.index {
            // if the index was specified we will update existing record
            RefDB::get_offset(data, idx as usize)?
        } else {
            // otherwise either find a record with the supplied name or first available slot
            RefDB::find_write_offset(data, &record.name)?
        };
        let data_end = offset + record.get_size();
        check_data_len(data, data_end)?;
        let (stored_counter, stored_name) = RefDB::get_record_counter_and_name(data, offset)?;
        if stored_counter == 0 {
            return Ok(0);
        }
        // if the counter was specified we check that value is equal to stored,
        // to make sure there were no intermediate updates
        if record.counter > 0 && stored_counter != record.counter as usize {
            return Err(ProgramError::Custom(409));
        }
        // check that we are deleting record with matching name
        if record.name != stored_name {
            return Err(ProgramError::Custom(409));
        }
        // update data and counters
        let counter = RefDB::get_storage_counter(data)?;
        if (counter as u32) < u32::MAX {
            RefDB::set_storage_counter(data, counter + 1)?;
        } else {
            RefDB::set_storage_counter(data, 1)?;
        }
        let active_records = RefDB::get_active_records(data)?;
        if active_records > 0 {
            RefDB::set_active_records(data, active_records - 1)?;
        }
        data[offset..data_end].fill(0);

        Ok(record.get_size())
    }
/// Deletes the record from the storage.
/// Uses the index if provided or searches the record by name.
/// If counter is provided it checks that it is equal to stored or error is returned.
Deletes the record from the storage.
Uses the index if provided or searches the record by name.
If counter is provided it checks that it is equal to stored or error is returned.
Deletes the record from the storage . Uses the index if provided or searches the record by name . If counter is provided it checks that it is equal to stored or error is returned .
pub fn delete(data: &mut [u8], record: &Record) -> Result<usize, ProgramError> {
        let offset = if let Some(idx) = record.index {
            // if the index was specified we will update existing record
            RefDB::get_offset(data, idx as usize)?
        } else {
            // otherwise either find a record with the supplied name or first available slot
            RefDB::find_write_offset(data, &record.name)?
        };
        let data_end = offset + record.get_size();
        check_data_len(data, data_end)?;
        let (stored_counter, stored_name) = RefDB::get_record_counter_and_name(data, offset)?;
        if stored_counter == 0 {
            return Ok(0);
        }
        // if the counter was specified we check that value is equal to stored,
        // to make sure there were no intermediate updates
        if record.counter > 0 && stored_counter != record.counter as usize {
            return Err(ProgramError::Custom(409));
        }
        // check that we are deleting record with matching name
        if record.name != stored_name {
            return Err(ProgramError::Custom(409));
        }
        // update data and counters
        let counter = RefDB::get_storage_counter(data)?;
        if (counter as u32) < u32::MAX {
            RefDB::set_storage_counter(data, counter + 1)?;
        } else {
            RefDB::set_storage_counter(data, 1)?;
        }
        let active_records = RefDB::get_active_records(data)?;
        if active_records > 0 {
            RefDB::set_active_records(data, active_records - 1)?;
        }
        data[offset..data_end].fill(0);
        Ok(record.get_size())
    }
pub fn delete ( data : & mut [ u8 ] , record : & Record ) -> Result < usize , ProgramError > { let offset = if let Some ( idx ) = record . index { // if the index was specified we will update existing record RefDB :: get_offset ( data , idx as usize ) ? } else { // otherwise either find a record with the supplied name or first available slot RefDB :: find_write_offset ( data , & record . name ) ? } ; let data_end = offset + record . get_size ( ) ; check_data_len ( data , data_end ) ? ; let ( stored_counter , stored_name ) = RefDB :: get_record_counter_and_name ( data , offset ) ? ; if stored_counter == 0 { return Ok ( 0 ) ; } // if the counter was specified we check that value is equal to stored, // to make sure there were no intermediate updates if record . counter > 0 && stored_counter != record . counter as usize { return Err ( ProgramError :: Custom ( 409 ) ) ; } // check that we are deleting record with matching name if record . name != stored_name { return Err ( ProgramError :: Custom ( 409 ) ) ; } // update data and counters let counter = RefDB :: get_storage_counter ( data ) ? ; if ( counter as u32 ) < u32 :: MAX { RefDB :: set_storage_counter ( data , counter + 1 ) ? ; } else { RefDB :: set_storage_counter ( data , 1 ) ? ; } let active_records = RefDB :: get_active_records ( data ) ? ; if active_records > 0 { RefDB :: set_active_records ( data , active_records - 1 ) ? ; } data [ offset .. data_end ] . fill ( 0 ) ; Ok ( record . get_size ( ) ) }
Deletes the record from the storage.
Deletes the record from the storage .
data
&mut [u8]
record
&Record
data
&mut [u8]
record
&Record