Comments (4)
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.
I like to have this too :)
from edit.
Implement the feature. Please give feedback :)
edit = { git = "https://github.com/Gottox/edit.git", branch = "tempfile_builder" }
from edit.
from edit.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from edit.