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 aPaththat 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.
§Errors
This function returns an error if the file cannot be opened, or if the seek or write operations fail.
§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(())
}