this post was submitted on 15 Aug 2023
12 points (100.0% liked)

Rust Programming

8150 readers
14 users here now

founded 5 years ago
MODERATORS
 

I want to build a small gui application in rust. What are my options for application storage? I have heard of the confi crate but I want to save a bit more than just configuration. Is there a crate that handles this for me easily?

top 5 comments
sorted by: hot top controversial new old
[–] Vorpal@programming.dev 11 points 1 year ago (1 children)

Be sure to treat state and configuration separately. It doesn't matter on Windows as far as I know (they go in the same location), but on Linux those are supposed to go in different places.

Many programs get this wrong, and it is quite annoying as I track my config files in git. I don't want a diff just because the list of recently opened files changed! Or even worse: the program stores the last window size and position in the config file... (looking at you KDE!)

Here are some libraries I found to help with this in a cross platform way:

I haven't tried either, haven't written such a program yet.

As for how to store data, there are indeed many options, depending on your needs:

  • Plain text based formats (toml, yaml, JSON, ini, ...) can be good for configs and basic state. As a bonus it let's the user easily manage the file in version control if they are so inclined.
  • Databases (SQLite mostly)
  • Custom formats (binary files in a directory structure is often used for browser caches for example) .

Without knowing more it is hard to give specific advise.

[–] CMahaff@lemm.ee 3 points 1 year ago

Thanks for the link to "dirs" - I wish I'd known about it before I implemented a (worse) version just using the home crate.

[–] anlumo@feddit.de 4 points 1 year ago

For Linux, here is the spec: https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.6.html

macOS has the NSSearchPathForDirectoriesInDomains API.

For Windows, there’s also an API for that, but I don’t know it offhand.

[–] AngryClosetMonkey@feddit.ch 3 points 1 year ago

It depends on how you want to store your data. Every OS has a standard for where applications should store their data. You should store your data at the appropriate path. If you have structured data against which you want to run queries you could use a sqlite DB (the sqlx crate supports sqlite) instead of just a bunch of config files.

[–] raffomania@lemmy.world 2 points 1 year ago

For storing state, I’d look at SQLite first. turbosql is a wrapper that looks like it’s a joy to use and I’ve been looking for an excuse to try it for a while :)