rlg::utils

Function truncate_file

Source
pub async fn truncate_file(path: &Path, size: u64) -> Result<()>
Expand description

Truncates the file at the given path to the specified size.

§Arguments

  • path - A reference to a Path that holds the file path to truncate.
  • size - The size (in bytes) to truncate the file to.

§Returns

A std::io::Result<()> which is Ok(()) if the operation succeeds, or an error if it fails.

§Examples

use rlg::utils::truncate_file;
use std::path::Path;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let path = Path::new("example.log");
    truncate_file(&path, 1024).await?;
    println!("File truncated successfully");
    Ok(())
}