#xdg-base #directories #config-directory #xdg #dirs #path

etcetera

An unopinionated library for obtaining configuration, data, cache, & other directories

14 releases (9 breaking)

0.10.0 Mar 3, 2025
0.8.0 Apr 26, 2023
0.4.0 May 9, 2022
0.3.2 Nov 26, 2020
0.1.0 May 16, 2020

#3 in Configuration

Download history 253598/week @ 2024-11-21 183219/week @ 2024-11-28 260756/week @ 2024-12-05 284879/week @ 2024-12-12 154418/week @ 2024-12-19 104341/week @ 2024-12-26 253542/week @ 2025-01-02 318924/week @ 2025-01-09 253252/week @ 2025-01-16 309425/week @ 2025-01-23 311241/week @ 2025-01-30 374272/week @ 2025-02-06 416586/week @ 2025-02-13 495959/week @ 2025-02-20 514987/week @ 2025-02-27 517621/week @ 2025-03-06

2,039,409 downloads per month
Used in 993 crates (60 directly)

MIT/Apache

52KB
462 lines

crates.io version crates.io revdeps documentation license

Etcetera

This is a Rust library that allows you to determine the locations of configuration, data, cache & other files for your application. Existing Rust libraries generally do not give you a choice in terms of which standards/conventions they follow. Etcetera, on the other hand, gives you the choice.

MSRV: 1.70.0 (You need to pin home dependency to <0.5.11, otherwise it is 1.81.0)

Conventions

Etcetera supports the following conventions:

Strategies

Etcetera has 2 modes of operation: BaseStrategy & AppStrategy:

  • With BaseStrategy, you just get the location of the respective directory. For eg. for config_dir():
    • XDG: ~/.config
    • Apple: ~/Library/Preferences
    • Windows: ~\AppData\Roaming
  • With AppStrategy, you provide additional information to get the location of your app directory. For eg. if you provide the following details: { top_level_domain: "org", author: "Acme Corp", app_name: "Frobnicator Plus" }, you'll get:
    • XDG: ~/.config/frobnicator-plus
    • Unix: ~/.frobnicator-plus
    • Apple: ~/Library/Preferences/org.acme-corp.Frobnicator-Plus
    • Windows: ~\AppData\Roaming\Acme Corp\Frobnicator Plus

Note: the location of the home (~) is determined by the home crate.

Convenience functions

Etcetera also provides convenience functions for selecting the appropriate strategy on each platform:

  • base_strategy::choose_base_strategy & app_strategy::choose_app_strategy: Uses Windows on Windows & XDG everywhere else. This is used by most CLI tools & some GUI tools on each platform.
  • base_strategy::choose_native_strategy & app_strategy::choose_native_strategy: Uses Windows on Windows, Apple on macOS/iOS, & XDG everywhere else. This is used by most GUI applications on each platform.

See the documentation for examples.

Dependencies

~0–8MB
~54K SLoC