Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Store files as names (String) or as std::fs::File – which is preferable?
I’m aiming to build an intermediate layer in between an application and the file system. This layer has to access (read) existing files and write data into files. Most of the time the intermediate layer makes decisions based on (file-) names without reading or writing files themselves.
So what’s the best way to store these files?
From my beginners point of view there are at least two ways to do that. And I’d like to hear some full fledged rustaceans’ opinions.
First option is to store filenames as Strings. Whenever it comes to read from a particular file I’ve to create the std::fs::File from stored String(s). I bet that takes some runtime but should release the handles nicely once the content of a file is read.
Second option is to store std::fs::File right from the start. I’d think that the price for the better performance might be some blocking in the underlying file system. And I imagine the ownership of these handles to turn challenging – especially when this intermediate layer has to operate within a multi-threaded environment.
What’s the recommended way to store a number of names / files?
Best regards,
Chris
4 posts - 3 participants
🏷️ rust_feed