deep_causality_tempfile 0.1.1

Scratch files and directories removed on drop, std only, for the deep_causality test suites.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 2 items with examples
  • Size
  • Source code size: 28.2 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 291.3 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • deepcausality-rs/deep_causality
    283 19 5
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • marvin-hansen

DeepCausality Tempfile

Crates.io Docs.rs MIT licensed

The crate provides scratch files and directories for the DeepCausality test suites. It depends only on std. It has two types:

  • TempDir is a new, empty directory under std::env::temp_dir(). Dropping it removes the directory and everything inside it.
  • NamedTempFile is a new, empty file under std::env::temp_dir(). You write to it through std::io::Write, and dropping it removes the file. NamedTempFile::with_suffix(".csv") ends the file name with an extension.
use std::io::Write;
use deep_causality_tempfile::{NamedTempFile, TempDir};

let dir = TempDir::new().unwrap();
std::fs::write(dir.path().join("table.csv"), b"a,b\n").unwrap();

let mut f = NamedTempFile::with_suffix(".csv").unwrap();
f.write_all(b"a,b\n1,2\n").unwrap();
f.flush().unwrap();
assert_eq!(std::fs::read(f.path()).unwrap(), b"a,b\n1,2\n");

Creation never opens a path that already exists. On Unix, files are created with mode 0o600 and directories with mode 0o700, before the umask applies. A suffix that contains / or \ is rejected with ErrorKind::InvalidInput.