pub fn compact(&mut self, new_start_index: u64) -> Result<(), LogError> {
        self.flush()?;

        // Seek to the start index. This will also change the file cursor, allowing io::copy to correctly operate.
        self.seek(new_start_index)?;

        let mut temp_file_path = std::env::temp_dir().to_path_buf();
        temp_file_path.set_file_name(format!("log-{}", rand::random::<u32>()));
        let mut new_file = AdvisoryFileLock::new(
            temp_file_path.as_path(),
            advisory_lock::FileLockMode::Exclusive,
        )?;

        new_file.write_all(&mut new_start_index.to_le_bytes())?;
        io::copy(&mut *self.file, &mut *new_file)?;

        std::fs::rename(temp_file_path, self.path.clone())?;
        self.file = new_file;

        self.len = self.len - (new_start_index - self.first_index);
        self.first_index = new_start_index;

        Ok(())
    }
/// Compact the log, removing entries older than `new_start_index`.
///
/// This is done by copying all entries `>= new_start_index` to a temporary file, than overriding the
/// old log file once the copy is complete.
///
/// Before compacting, the log is flushed.
Compact the log, removing entries older than `new_start_index`.
This is done by copying all entries `>= new_start_index` to a temporary file, than overriding the
old log file once the copy is complete.

Before compacting, the log is flushed.
Compact the log removing entries older than ` new_start_index ` . This is done by copying all entries ` > = new_start_index ` to a temporary file than overriding the old log file once the copy is complete . Before compacting the log is flushed .
pub fn compact(&mut self, new_start_index: u64) -> Result<(), LogError> {
        self.flush()?;
        // Seek to the start index. This will also change the file cursor, allowing io::copy to correctly operate.
        self.seek(new_start_index)?;
        let mut temp_file_path = std::env::temp_dir().to_path_buf();
        temp_file_path.set_file_name(format!("log-{}", rand::random::<u32>()));
        let mut new_file = AdvisoryFileLock::new(
            temp_file_path.as_path(),
            advisory_lock::FileLockMode::Exclusive,
        )?;
        new_file.write_all(&mut new_start_index.to_le_bytes())?;
        io::copy(&mut *self.file, &mut *new_file)?;
        std::fs::rename(temp_file_path, self.path.clone())?;
        self.file = new_file;
        self.len = self.len - (new_start_index - self.first_index);
        self.first_index = new_start_index;
        Ok(())
    }
pub fn compact ( & mut self , new_start_index : u64 ) -> Result < ( ) , LogError > { self . flush ( ) ? ; // Seek to the start index. This will also change the file cursor, allowing io::copy to correctly operate. self . seek ( new_start_index ) ? ; let mut temp_file_path = std :: env :: temp_dir ( ) . to_path_buf ( ) ; temp_file_path . set_file_name ( format ! ( " " rand random u32 ( ) ) ) ; let mut new_file = AdvisoryFileLock :: new ( temp_file_path . as_path ( ) , advisory_lock :: FileLockMode :: Exclusive , ) ? ; new_file . write_all ( & mut new_start_index . to_le_bytes ( ) ) ? ; io :: copy ( & mut * self . file , & mut * new_file ) ? ; std :: fs :: rename ( temp_file_path , self . path . clone ( ) ) ? ; self . file = new_file ; self . len = self . len - ( new_start_index - self . first_index ) ; self . first_index = new_start_index ; Ok ( ( ) ) }
Compact the log, removing entries older than `new_start_index`.
Compact the log removing entries older than ` new_start_index ` .
&mut self
new_start_index
u64