diff --git a/.clippy.toml b/.clippy.toml index 0a54853..16caf02 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1 @@ -msrv = "1.36.0" +msrv = "1.60.0" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63f3e85..7228ce2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,38 +2,41 @@ name: CI on: [push, pull_request] -env: - minrust: 1.40.0 # Also update in Cargo.toml - jobs: Lints: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 - uses: dtolnay/rust-toolchain@stable with: components: clippy, rustfmt - - - run: cargo fmt --check - - run: cargo clippy -- -D warnings + - name: Check formatting + run: cargo fmt --check + continue-on-error: true + - name: Run clippy + run: cargo clippy -- -D warnings + if: always() Test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 - uses: dtolnay/rust-toolchain@stable - - run: cargo check --features serde + - name: Cargo check on serde feature + run: cargo check --features serde - run: cargo test MSRV: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install ${{ env.minrust }} toolchain - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ env.minrust }} - - run: cargo test + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + - name: Install cargo-msrv + run: cargo install cargo-msrv + - name: Run cargo-msrv verify + run: cargo msrv verify diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index daa1e8f..e89999a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,7 +10,8 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 - uses: dtolnay/rust-toolchain@nightly - name: Build docs @@ -21,7 +22,7 @@ jobs: echo '' > _site/index.html mv target/doc/* _site - - uses: actions/upload-pages-artifact@v1 + - uses: actions/upload-pages-artifact@v3 deploy: needs: build @@ -38,4 +39,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v1 + uses: actions/deploy-pages@v4 diff --git a/Cargo.toml b/Cargo.toml index 6539fc6..b8066cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "xdg" -version = "2.5.2" +version = "2.6.0" description = "A library for storing and retrieving files according to XDG Base Directory specification" homepage = "https://github.com/whitequark/rust-xdg" repository = "https://github.com/whitequark/rust-xdg" documentation = "https://docs.rs/xdg/" readme = "README.md" -edition = "2018" -rust-version = "1.40.0" # Also update in .github/workflows/ci.yml +edition = "2021" +rust-version = "1.60.0" # Also update in .github/workflows/ci.yml categories = ["filesystem"] -keywords = ["linux", "configuration"] +keywords = ["linux", "configuration", "xdg"] license = "Apache-2.0 OR MIT" authors = [ "Ben Longbons ", diff --git a/README.md b/README.md index 04a299a..22e4288 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ -rust-xdg -======== +# rust-xdg + +[![CI](https://github.com/whitequark/rust-xdg/actions/workflows/ci.yml/badge.svg)](https://github.com/whitequark/rust-xdg/actions/workflows/ci.yml) +[![Documentation](https://github.com/whitequark/rust-xdg/actions/workflows/docs.yml/badge.svg)](https://github.com/whitequark/rust-xdg/actions/workflows/docs.yml) +![Crates.io Version](https://img.shields.io/crates/v/xdg?color=%23a55e08&link=https%3A%2F%2Fcrates.io%2Fcrates%2Fxdg) +![rustc version](https://img.shields.io/badge/msrv-1.60.0-lightgray.svg) + rust-xdg is a library that makes it easy to follow the X Desktop Group specifications. @@ -8,25 +13,22 @@ Currently, only [XDG Base Directory][basedir] specification is implemented. [basedir]: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html -Installation ------------- +## Installation Add the following to `Cargo.toml`: ```toml [dependencies] -xdg = "^2.5" +xdg = "^2.6" ``` -Examples --------- +## Examples See [documentation](https://whitequark.github.io/rust-xdg/xdg/). -License -------- +## License -rust-xdg is distributed under the terms of both the MIT license +**rust-xdg** is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) diff --git a/src/base_directories.rs b/src/base_directories.rs index f27bffc..93f6bfc 100644 --- a/src/base_directories.rs +++ b/src/base_directories.rs @@ -115,7 +115,7 @@ pub struct Error { } impl Error { - fn new(kind: ErrorKind) -> Error { + const fn new(kind: ErrorKind) -> Error { Error { kind } } } @@ -263,21 +263,21 @@ impl BaseDirectories { BaseDirectories::with_env(prefix, profile, &|name| env::var_os(name)) } - fn with_env(prefix: P1, profile: P2, env_var: &T) -> BaseDirectories - where - P1: AsRef, - P2: AsRef, - T: Fn(&str) -> Option, - { + fn with_env(prefix: P1, profile: P2, env_var: &T) -> BaseDirectories + where + P1: AsRef, + P2: AsRef, + T: ?Sized + Fn(&str) -> Option, + { BaseDirectories::with_env_impl(prefix.as_ref(), profile.as_ref(), env_var) } - fn with_env_impl(prefix: &Path, profile: &Path, env_var: &T) -> BaseDirectories - where - T: Fn(&str) -> Option, - { + fn with_env_impl(prefix: &Path, profile: &Path, env_var: &T) -> BaseDirectories + where + T: ?Sized + Fn(&str) -> Option, + { fn abspath(path: OsString) -> Option { - let path = PathBuf::from(path); + let path: PathBuf = PathBuf::from(path); if path.is_absolute() { Some(path) } else { @@ -286,7 +286,7 @@ impl BaseDirectories { } fn abspaths(paths: OsString) -> Option> { - let paths = env::split_paths(&paths) + let paths: Vec = env::split_paths(&paths) .map(PathBuf::from) .filter(|path| path.is_absolute()) .collect::>(); @@ -300,7 +300,7 @@ impl BaseDirectories { // This crate only supports Unix, and the behavior of `std::env::home_dir()` is only // problematic on Windows. #[allow(deprecated)] - let home = std::env::home_dir(); + let home: Option = std::env::home_dir(); let data_home = env_var("XDG_DATA_HOME") .and_then(abspath) @@ -323,7 +323,7 @@ impl BaseDirectories { .unwrap_or(vec![PathBuf::from("/etc/xdg")]); let runtime_dir = env_var("XDG_RUNTIME_DIR").and_then(abspath); // optional - let prefix = PathBuf::from(prefix); + let prefix: PathBuf = PathBuf::from(prefix); BaseDirectories { user_prefix: prefix.join(profile), shared_prefix: prefix, @@ -344,7 +344,7 @@ impl BaseDirectories { // do not allow recovery. fs::read_dir(runtime_dir) .map_err(|e| Error::new(XdgRuntimeDirInaccessible(runtime_dir.clone(), e)))?; - let permissions = fs::metadata(runtime_dir) + let permissions: u32 = fs::metadata(runtime_dir) .map_err(|e| Error::new(XdgRuntimeDirInaccessible(runtime_dir.clone(), e)))? .permissions() .mode(); @@ -448,7 +448,7 @@ impl BaseDirectories { /// `XDG_CONFIG_DIRS`. pub fn find_config_file>(&self, path: P) -> Option { read_file( - self.config_home.as_ref().map(|home| home.as_path()), + self.config_home.as_deref(), &self.config_dirs, &self.user_prefix, &self.shared_prefix, @@ -462,7 +462,7 @@ impl BaseDirectories { /// to highest. pub fn find_config_files>(&self, path: P) -> FileFindIterator { FileFindIterator::new( - self.config_home.as_ref().map(|home| home.as_path()), + self.config_home.as_deref(), &self.config_dirs, &self.user_prefix, &self.shared_prefix, @@ -475,7 +475,7 @@ impl BaseDirectories { /// `XDG_DATA_DIRS`. pub fn find_data_file>(&self, path: P) -> Option { read_file( - self.data_home.as_ref().map(|home| home.as_path()), + self.data_home.as_deref(), &self.data_dirs, &self.user_prefix, &self.shared_prefix, @@ -489,7 +489,7 @@ impl BaseDirectories { /// to highest. pub fn find_data_files>(&self, path: P) -> FileFindIterator { FileFindIterator::new( - self.data_home.as_ref().map(|home| home.as_path()), + self.data_home.as_deref(), &self.data_dirs, &self.user_prefix, &self.shared_prefix, @@ -501,7 +501,7 @@ impl BaseDirectories { /// cache file, or `None`. Searches `XDG_CACHE_HOME`. pub fn find_cache_file>(&self, path: P) -> Option { read_file( - self.cache_home.as_ref().map(|home| home.as_path()), + self.cache_home.as_deref(), &Vec::new(), &self.user_prefix, &self.shared_prefix, @@ -513,7 +513,7 @@ impl BaseDirectories { /// application state file, or `None`. Searches `XDG_STATE_HOME`. pub fn find_state_file>(&self, path: P) -> Option { read_file( - self.state_home.as_ref().map(|home| home.as_path()), + self.state_home.as_deref(), &Vec::new(), &self.user_prefix, &self.shared_prefix, @@ -541,7 +541,7 @@ impl BaseDirectories { /// if that is not possible, an error is returned. pub fn create_config_directory>(&self, path: P) -> io::Result { create_directory( - self.config_home.as_ref().map(|home| home.as_path()), + self.config_home.as_deref(), &self.user_prefix.join(path), ) } @@ -550,7 +550,7 @@ impl BaseDirectories { /// but for a data directory in `XDG_DATA_HOME`. pub fn create_data_directory>(&self, path: P) -> io::Result { create_directory( - self.data_home.as_ref().map(|home| home.as_path()), + self.data_home.as_deref(), &self.user_prefix.join(path), ) } @@ -559,7 +559,7 @@ impl BaseDirectories { /// but for a cache directory in `XDG_CACHE_HOME`. pub fn create_cache_directory>(&self, path: P) -> io::Result { create_directory( - self.cache_home.as_ref().map(|home| home.as_path()), + self.cache_home.as_deref(), &self.user_prefix.join(path), ) } @@ -568,7 +568,7 @@ impl BaseDirectories { /// but for an application state directory in `XDG_STATE_HOME`. pub fn create_state_directory>(&self, path: P) -> io::Result { create_directory( - self.state_home.as_ref().map(|home| home.as_path()), + self.state_home.as_deref(), &self.user_prefix.join(path), ) } @@ -588,7 +588,7 @@ impl BaseDirectories { /// `XDG_CONFIG_DIRS`. pub fn list_config_files>(&self, path: P) -> Vec { list_files( - self.config_home.as_ref().map(|home| home.as_path()), + self.config_home.as_deref(), &self.config_dirs, &self.user_prefix, &self.shared_prefix, @@ -600,7 +600,7 @@ impl BaseDirectories { /// only the first occurence of every distinct filename is returned. pub fn list_config_files_once>(&self, path: P) -> Vec { list_files_once( - self.config_home.as_ref().map(|home| home.as_path()), + self.config_home.as_deref(), &self.config_dirs, &self.user_prefix, &self.shared_prefix, @@ -613,7 +613,7 @@ impl BaseDirectories { /// `XDG_DATA_DIRS`. pub fn list_data_files>(&self, path: P) -> Vec { list_files( - self.data_home.as_ref().map(|home| home.as_path()), + self.data_home.as_deref(), &self.data_dirs, &self.user_prefix, &self.shared_prefix, @@ -625,7 +625,7 @@ impl BaseDirectories { /// only the first occurence of every distinct filename is returned. pub fn list_data_files_once>(&self, path: P) -> Vec { list_files_once( - self.data_home.as_ref().map(|home| home.as_path()), + self.data_home.as_deref(), &self.data_dirs, &self.user_prefix, &self.shared_prefix, @@ -637,7 +637,7 @@ impl BaseDirectories { /// in directories with path `path` in `XDG_CACHE_HOME`. pub fn list_cache_files>(&self, path: P) -> Vec { list_files( - self.cache_home.as_ref().map(|home| home.as_path()), + self.cache_home.as_deref(), &Vec::new(), &self.user_prefix, &self.shared_prefix, @@ -649,7 +649,7 @@ impl BaseDirectories { /// in directories with path `path` in `XDG_STATE_HOME`. pub fn list_state_files>(&self, path: P) -> Vec { list_files( - self.state_home.as_ref().map(|home| home.as_path()), + self.state_home.as_deref(), &Vec::new(), &self.user_prefix, &self.shared_prefix,