Giter Site home page Giter Site logo

rs-mktemp's Introduction

mktemp

Released API docs Crates.io MPL licensed CI

This module provides a simple way of creating temporary files and directories where their lifetime is defined by the scope they exist in.

Once the variable goes out of scope, the underlying file system resource is removed.

See documentation for full API, and other use cases.

Example

use mktemp::Temp;

{
  let temp_file = Temp::new_file().unwrap();
  let file = fs::File::open(temp_file).unwrap();
} // temp_file is cleaned from the fs here

Contributors

Special thanks to our contributors! Contributors

License

MPL v2

rs-mktemp's People

Contributors

samgiles avatar l-as avatar nstinus avatar samueltardieu avatar dependabot[bot] avatar pgerber avatar arkaitzj avatar jrop avatar jmgao avatar koutheir avatar mattgeddes avatar nazar-pc avatar sanpii avatar

Stargazers

robin avatar IogaMaster avatar Wojciech Kałuża avatar fx-kirin avatar Esteban Blanc avatar  avatar Manuel avatar Terkwood avatar Tomáš Jašek avatar  avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

rs-mktemp's Issues

Release flag and method are inefficient; operate by value instead

It’d be more efficient to have release() consume self and return the PathBuf:

pub fn release(self) -> PathBuf {
    let path = mem::replace(&mut self.path, PathBuf::new());
    mem::forget(self);
    path
}

That way you don’t need to allocate twice just to get the path out as a PathBuf.

This also allows you to scrap the flag _release altogether.

Provide a mechanism for retaining file

The default behaviour is nice for writing tests since everything is cleaned up afterwards. But painful if the tests fail -- it becomes hard to debug because it's not possible to see what is in the file that you've just deleted.

It would be nice to have a mechanism to stop file deletions after, say, a panic.

Upgrade uuid

uuid 0.8 is deprecated since april 2022. Can it be upgraded?

Don't panic on remove if the file does not exist

The current implementation panic in the Drop impl if removing the file failed. It panics even if the remove failed due to the file not existing. The purpose of the temp file is to make the file disappear, so why should that panic?

Support creating temporary file with particular extension

I have a use case where I'm generating a temporary file and then opening it with a text editor. The editor uses the file extension to decide which syntax highlighter to use so it would be useful to be able to specify the extension by hand.

Split Temp into TempFile and TempDir

The _type flag is wasteful and makes for trivially more expensive construction and destruction. It’d be more efficient—and I would argue more ergonomic—to split the Temp type into two types, TempFile and TempDir. (I’m not going to suggest phantom types, because they’re more complex for no gain that is evident to me.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.