#temporary-files

mktemp-rs

A thin wrapper around libc's mkstemps and mkdtemp

2 unstable releases

0.2.0 Dec 22, 2018
0.1.0 Dec 19, 2018

#1588 in Filesystem

Download history 14/week @ 2024-07-20 29/week @ 2024-07-27 15/week @ 2024-08-03 10/week @ 2024-08-10 12/week @ 2024-08-17 10/week @ 2024-08-24 13/week @ 2024-08-31 12/week @ 2024-09-07 15/week @ 2024-09-14 56/week @ 2024-09-21 32/week @ 2024-09-28 49/week @ 2024-10-05 25/week @ 2024-10-12 24/week @ 2024-10-19 290/week @ 2024-10-26 141/week @ 2024-11-02

483 downloads per month

MIT/Apache

10KB
151 lines

mktemp-rs

A thin wrapper around libc's mkstemps and mkdtemp.

Quick Start (Documentation)

Cargo.toml:

name = "my-awesome-project"
version = "0.1.0"
authors = ["me"]

[dependencies]
+mktemp-rs = "0.1.0"

main.rs:

use std::fs;
use std::io::{Seek, SeekFrom, Read, Write};
use mktemp::TempFile;

fn readme() {
    let path;
    {
        let mut tf = TempFile::new("my-temp-file-", ".txt").expect("Failed to create tempfile");
        let mut buf = [0u8; 12];
        tf.write(b"Hello world!").expect("Failed to write to tempfile");
        tf.seek(SeekFrom::Start(0)).expect("Failed to seek in tempfile");
        tf.read(&mut buf).expect("Failed to read tempfile");
        assert_eq!(&buf, b"Hello world!");
        path = tf.path().to_string();
    }
    assert!(fs::metadata(&path).is_err());
}

mktemp-rs currently only support Unix platforms. As always, pull requests are welcome.

Tests

readme tests the example in this readme.

temp_dir tests various TempDir functions.

temp_file tests various TempFile functions.

Coding Style

Obey rustfmt and Rust 2018 conventions.

Contributing

Pull requests are always welcome. See TODO.

Versioning

This project adheres to Semantic Versioning.

Changes are documented in the Changelog.

See the tags on this repository for available releases.

Authors

See the list of contributors.

License

mktemp-rs is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Acknowledgments

  • mkstemp by William Orr for inspiration and code base.

Dependencies

~44KB