Function tempfile::spooled_tempfile

source ·
pub fn spooled_tempfile(max_size: usize) -> SpooledTempFile 
Expand description

Create a new spooled temporary file.

§Security

This variant is secure/reliable in the presence of a pathological temporary file cleaner.

§Resource Leaking

The temporary file will be automatically removed by the OS when the last handle to it is closed. This doesn’t rely on Rust destructors being run, so will (almost) never fail to clean up the temporary file.

§Examples

use tempfile::spooled_tempfile;
use std::io::{self, Write};

let mut file = spooled_tempfile(15);

writeln!(file, "short line")?;
assert!(!file.is_rolled());

// as a result of this write call, the size of the data will exceed
// `max_size` (15), so it will be written to a temporary file on disk,
// and the in-memory buffer will be dropped
writeln!(file, "marvin gardens")?;
assert!(file.is_rolled());