Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Rust 2021 #71

Merged
merged 8 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.36.0"
msrv = "1.60.0"
33 changes: 18 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +22,7 @@ jobs:
echo '<meta http-equiv="refresh" content="0;url=xdg/index.html">' > _site/index.html
mv target/doc/* _site

- uses: actions/upload-pages-artifact@v1
- uses: actions/upload-pages-artifact@v3

deploy:
needs: build
Expand All @@ -38,4 +39,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
uses: actions/deploy-pages@v4
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <b.r.longbons@gmail.com>",
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
Expand Down
64 changes: 32 additions & 32 deletions src/base_directories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct Error {
}

impl Error {
fn new(kind: ErrorKind) -> Error {
const fn new(kind: ErrorKind) -> Error {
Error { kind }
}
}
Expand Down Expand Up @@ -263,21 +263,21 @@ impl BaseDirectories {
BaseDirectories::with_env(prefix, profile, &|name| env::var_os(name))
}

fn with_env<P1, P2, T: ?Sized>(prefix: P1, profile: P2, env_var: &T) -> BaseDirectories
where
P1: AsRef<Path>,
P2: AsRef<Path>,
T: Fn(&str) -> Option<OsString>,
{
fn with_env<P1, P2, T>(prefix: P1, profile: P2, env_var: &T) -> BaseDirectories
where
P1: AsRef<Path>,
P2: AsRef<Path>,
T: ?Sized + Fn(&str) -> Option<OsString>,
{
BaseDirectories::with_env_impl(prefix.as_ref(), profile.as_ref(), env_var)
}

fn with_env_impl<T: ?Sized>(prefix: &Path, profile: &Path, env_var: &T) -> BaseDirectories
where
T: Fn(&str) -> Option<OsString>,
{
fn with_env_impl<T>(prefix: &Path, profile: &Path, env_var: &T) -> BaseDirectories
where
T: ?Sized + Fn(&str) -> Option<OsString>,
{
fn abspath(path: OsString) -> Option<PathBuf> {
let path = PathBuf::from(path);
let path: PathBuf = PathBuf::from(path);
if path.is_absolute() {
Some(path)
} else {
Expand All @@ -286,7 +286,7 @@ impl BaseDirectories {
}

fn abspaths(paths: OsString) -> Option<Vec<PathBuf>> {
let paths = env::split_paths(&paths)
let paths: Vec<PathBuf> = env::split_paths(&paths)
.map(PathBuf::from)
.filter(|path| path.is_absolute())
.collect::<Vec<_>>();
Expand All @@ -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<PathBuf> = std::env::home_dir();

let data_home = env_var("XDG_DATA_HOME")
.and_then(abspath)
Expand All @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -448,7 +448,7 @@ impl BaseDirectories {
/// `XDG_CONFIG_DIRS`.
pub fn find_config_file<P: AsRef<Path>>(&self, path: P) -> Option<PathBuf> {
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,
Expand All @@ -462,7 +462,7 @@ impl BaseDirectories {
/// to highest.
pub fn find_config_files<P: AsRef<Path>>(&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,
Expand All @@ -475,7 +475,7 @@ impl BaseDirectories {
/// `XDG_DATA_DIRS`.
pub fn find_data_file<P: AsRef<Path>>(&self, path: P) -> Option<PathBuf> {
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,
Expand All @@ -489,7 +489,7 @@ impl BaseDirectories {
/// to highest.
pub fn find_data_files<P: AsRef<Path>>(&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,
Expand All @@ -501,7 +501,7 @@ impl BaseDirectories {
/// cache file, or `None`. Searches `XDG_CACHE_HOME`.
pub fn find_cache_file<P: AsRef<Path>>(&self, path: P) -> Option<PathBuf> {
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,
Expand All @@ -513,7 +513,7 @@ impl BaseDirectories {
/// application state file, or `None`. Searches `XDG_STATE_HOME`.
pub fn find_state_file<P: AsRef<Path>>(&self, path: P) -> Option<PathBuf> {
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,
Expand Down Expand Up @@ -541,7 +541,7 @@ impl BaseDirectories {
/// if that is not possible, an error is returned.
pub fn create_config_directory<P: AsRef<Path>>(&self, path: P) -> io::Result<PathBuf> {
create_directory(
self.config_home.as_ref().map(|home| home.as_path()),
self.config_home.as_deref(),
&self.user_prefix.join(path),
)
}
Expand All @@ -550,7 +550,7 @@ impl BaseDirectories {
/// but for a data directory in `XDG_DATA_HOME`.
pub fn create_data_directory<P: AsRef<Path>>(&self, path: P) -> io::Result<PathBuf> {
create_directory(
self.data_home.as_ref().map(|home| home.as_path()),
self.data_home.as_deref(),
&self.user_prefix.join(path),
)
}
Expand All @@ -559,7 +559,7 @@ impl BaseDirectories {
/// but for a cache directory in `XDG_CACHE_HOME`.
pub fn create_cache_directory<P: AsRef<Path>>(&self, path: P) -> io::Result<PathBuf> {
create_directory(
self.cache_home.as_ref().map(|home| home.as_path()),
self.cache_home.as_deref(),
&self.user_prefix.join(path),
)
}
Expand All @@ -568,7 +568,7 @@ impl BaseDirectories {
/// but for an application state directory in `XDG_STATE_HOME`.
pub fn create_state_directory<P: AsRef<Path>>(&self, path: P) -> io::Result<PathBuf> {
create_directory(
self.state_home.as_ref().map(|home| home.as_path()),
self.state_home.as_deref(),
&self.user_prefix.join(path),
)
}
Expand All @@ -588,7 +588,7 @@ impl BaseDirectories {
/// `XDG_CONFIG_DIRS`.
pub fn list_config_files<P: AsRef<Path>>(&self, path: P) -> Vec<PathBuf> {
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,
Expand All @@ -600,7 +600,7 @@ impl BaseDirectories {
/// only the first occurence of every distinct filename is returned.
pub fn list_config_files_once<P: AsRef<Path>>(&self, path: P) -> Vec<PathBuf> {
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,
Expand All @@ -613,7 +613,7 @@ impl BaseDirectories {
/// `XDG_DATA_DIRS`.
pub fn list_data_files<P: AsRef<Path>>(&self, path: P) -> Vec<PathBuf> {
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,
Expand All @@ -625,7 +625,7 @@ impl BaseDirectories {
/// only the first occurence of every distinct filename is returned.
pub fn list_data_files_once<P: AsRef<Path>>(&self, path: P) -> Vec<PathBuf> {
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,
Expand All @@ -637,7 +637,7 @@ impl BaseDirectories {
/// in directories with path `path` in `XDG_CACHE_HOME`.
pub fn list_cache_files<P: AsRef<Path>>(&self, path: P) -> Vec<PathBuf> {
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,
Expand All @@ -649,7 +649,7 @@ impl BaseDirectories {
/// in directories with path `path` in `XDG_STATE_HOME`.
pub fn list_state_files<P: AsRef<Path>>(&self, path: P) -> Vec<PathBuf> {
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,
Expand Down
Loading