Git Product home page Git Product logo

Comments (4)

milkey-mouse avatar milkey-mouse commented on August 23, 2024 1

It would be pretty easy to copy what edit_bytes is doing but with your own NamedTempFile, something like this:

let mut file = Builder::new()
    .suffix(".toml")
    .tempfile()?;
file.write(buf.as_ref())?;

let path = file.into_temp_path();
edit_file(&path)?;

let edited = fs::read(&path)?;

path.close()?;

It's slightly more annoying if you also want to convert to a UTF-8 string.

I'd be open to adding a function for this specific use case, like edit but taking a NamedTempFile as an argument; then the user can specify the directory, prefix, suffix, etc. with a tempfile::Builder.

On another note, if you're parsing TOML files (or any format supported by serde, in principle) with edit, I've written some code for validation with serde (both syntax-wise and for a specific config) and user-friendly in-editor syntax errors for another project of mine that could definitely be reused. (run storm config for a demo). I'm looking into refactoring this into its own crate (edit_toml?) but I haven't gotten around to it yet (and the implementation for storm isn't 100% complete).

from edit.

Gottox avatar Gottox commented on August 23, 2024

I like to have this too :)

from edit.

Gottox avatar Gottox commented on August 23, 2024

Implement the feature. Please give feedback :)

edit = { git = "https://github.com/Gottox/edit.git", branch = "tempfile_builder" }

from edit.

milkey-mouse avatar milkey-mouse commented on August 23, 2024

Fixed in v0.1.2.

from edit.

Related Issues (6)

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.