Skip to content

Commit

Permalink
Merge branch 'main' into feat/security
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera authored Jul 10, 2024
2 parents ef81a95 + 1b44edf commit 67ba5dc
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 172 deletions.
112 changes: 19 additions & 93 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,111 +1,37 @@
name: CI
name: "Continuous integration"
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: Build
ci:
name: CI checks
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- nightly
- 1.45.0
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
components: clippy
override: true
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v1
- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-make
- name: Build
if: ${{ matrix.rust != 'stable' }}
uses: actions-rs/cargo@v1
with:
command: make
args: ci-build
- name: Build and lint
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
if: ${{ matrix.rust == 'stable' }}
uses: actions-rs/cargo@v1
with:
command: make
args: ci-lint
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: rustfmt
override: true
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v1
- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-make
- name: Check format
uses: actions-rs/cargo@v1
with:
command: make
args: ci-format
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- nightly
- 1.45.0
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
toolchain: "1.61.0" # TODO: Pull this from Cargo.toml?
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: clippy, rustfmt
toolchain: ${{ matrix.rust }}
profile: minimal
components: ""
override: true
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v1
- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-make
- name: Run tests and generate coverage report
uses: actions-rs/cargo@v1
- uses: taiki-e/install-action@v2
with:
command: make
args: ci-test
- name: Upload to codecov.io
tool: cargo-msrv,cargo-tarpaulin
- run: ./scripts/ci/format
- run: ./scripts/ci/check
- run: ./scripts/ci/test
- run: cargo msrv verify
if: ${{ matrix.rust == 'stable' }}
- uses: coverallsapp/github-action@v2
if: ${{ matrix.rust == 'stable' }}
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true

file: lcov.info
format: lcov
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ target
Cargo.lock

# Backups from `cargo fmt`
*.rs.bk
*.rs.bk

# Coverage report
lcov.*
*.lcov
*.profraw
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[package]
name = "preferences"
version = "3.0.0"
version = "2.0.1-dev.0"
authors = ["Andy Barron <[email protected]>"]
edition = "2021"
rust-version = "1.61.0"
rust-version = "1.61.0" # syn

description = "Read and write user-specific application data (in stable Rust)"
documentation = "https://docs.rs/preferences"
repository = "https://github.com/AndyBarron/preferences-rs"
readme = "README.md"
keywords = ["preferences", "user", "data", "persistent", "storage"]
categories = ["config"]
license = "MIT-0"

[features]
Expand Down
31 changes: 13 additions & 18 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
The MIT License (MIT)
MIT No Attribution

Copyright (c) 2016 Andy Barron
Copyright 2024 Andy Barron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 changes: 0 additions & 42 deletions Makefile.toml

This file was deleted.

17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# preferences
_Read and write user-specific application data in Rust_

[![crates.io: preferences](https://img.shields.io/crates/v/preferences.svg?label=crates.io%3A%20preferences)](https://crates.io/crates/preferences)
[![Linux & OS X build status](https://img.shields.io/travis/AndyBarron/preferences-rs.svg?label=Linux%20%26%20OS%20X%20builds)](https://travis-ci.org/AndyBarron/preferences-rs)
[![Windows build status](https://img.shields.io/appveyor/ci/AndyBarron/preferences-rs.svg?label=Windows%20builds)](https://ci.appveyor.com/project/AndyBarron/preferences-rs)
[![Crates.io Version](https://img.shields.io/crates/v/preferences)](https://crates.io/crates/preferences)
![Crates.io MSRV](https://img.shields.io/crates/msrv/preferences)
[![Crates.io License](https://img.shields.io/crates/l/preferences)](https://github.com/andybarron/preferences-rs/blob/main/LICENSE.txt)
![Crates.io Total Downloads](https://img.shields.io/crates/d/preferences)

[![docs.rs](https://img.shields.io/docsrs/preferences)](https://docs.rs/preferences)
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/andybarron/preferences-rs/ci.yaml)](https://github.com/andybarron/preferences-rs/actions/workflows/ci.yaml)
[![Coveralls](https://img.shields.io/coverallsCoverage/github/andybarron/preferences-rs)](https://coveralls.io/github/andybarron/preferences-rs)

## Documentation
https://docs.rs/preferences

## Installation
Add the following to your `Cargo.toml`:

`preferences = "^1.1.0"`
```sh
cargo add preferences
```
2 changes: 2 additions & 0 deletions scripts/ci/check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
cargo clippy --all-targets -- -Dwarnings
2 changes: 2 additions & 0 deletions scripts/ci/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
cargo fmt -- --check --verbose
2 changes: 2 additions & 0 deletions scripts/ci/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
cargo tarpaulin -v --all-features --ignore-tests --out Lcov
2 changes: 2 additions & 0 deletions scripts/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
cargo release "$@"
29 changes: 19 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
#![allow(clippy::enum_glob_use)]
//! *Read and write user-specific application data*
//!
//! This crate allows Rust developers to store and retrieve user-local preferences and other
Expand Down Expand Up @@ -189,8 +191,8 @@ use std::string::FromUtf8Error;
pub mod security;

const DATA_TYPE: AppDataType = AppDataType::UserConfig;
static PREFS_FILE_EXTENSION: &'static str = ".prefs.json";
static DEFAULT_PREFS_FILENAME: &'static str = "prefs.json";
static PREFS_FILE_EXTENSION: &str = ".prefs.json";
static DEFAULT_PREFS_FILENAME: &str = "prefs.json";

/// Generic key-value store for user data.
///
Expand Down Expand Up @@ -241,7 +243,7 @@ impl std::error::Error for PreferencesError {

impl From<serde_json::Error> for PreferencesError {
fn from(e: serde_json::Error) -> Self {
PreferencesError::Json(e)
Self::Json(e)
}
}

Expand All @@ -250,19 +252,19 @@ impl From<FromUtf8Error> for PreferencesError {
let kind = ErrorKind::InvalidData;
let msg = "Preferences file contained invalid UTF-8";
let err = io::Error::new(kind, msg);
PreferencesError::Io(err)
Self::Io(err)
}
}

impl From<std::io::Error> for PreferencesError {
fn from(e: std::io::Error) -> Self {
PreferencesError::Io(e)
Self::Io(e)
}
}

impl From<AppDirsError> for PreferencesError {
fn from(e: AppDirsError) -> Self {
PreferencesError::Directory(e)
Self::Directory(e)
}
}

Expand Down Expand Up @@ -295,21 +297,27 @@ pub trait Preferences: Sized {
/// Saves the current state of this object. Implementation is platform-dependent, but the data
/// will be local to the active user.
///
/// # Failures
/// # Errors
/// If a serialization or file I/O error (e.g. permission denied) occurs.
fn save<S: AsRef<str>>(&self, app: &AppInfo, key: S) -> Result<(), PreferencesError>;
/// Loads this object's state from previously saved user data with the same `key`. This is
/// an instance method which completely overwrites the object's state with the serialized
/// data. Thus, it is recommended that you call this method immediately after instantiating
/// the preferences object.
///
/// # Failures
/// # Errors
/// If a deserialization or file I/O error (e.g. permission denied) occurs, or if no user data
/// exists at that `path`.
fn load<S: AsRef<str>>(app: &AppInfo, key: S) -> Result<Self, PreferencesError>;
/// Same as `save`, but writes the serialized preferences to an arbitrary writer.
///
/// # Errors
/// If a write or serialization error occurs.
fn save_to<W: Write>(&self, writer: &mut W) -> Result<(), PreferencesError>;
/// Same as `load`, but reads the serialized preferences from an arbitrary writer.
///
/// # Errors
/// If a read or deserialization error occurs.
fn load_from<R: Read>(reader: &mut R) -> Result<Self, PreferencesError>;
}

Expand Down Expand Up @@ -359,18 +367,19 @@ where
/// This makes no guarantees that the specified directory path actually *exists* (though you can
/// easily use `std::fs::create_dir_all(..)`). Returns `None` if the directory cannot be determined
/// or is not available on the current platform.
#[must_use]
pub fn prefs_base_dir() -> Option<PathBuf> {
get_data_root(AppDataType::UserConfig).ok()
}

#[cfg(test)]
mod tests {
use {AppInfo, Preferences, PreferencesMap};
use super::{AppInfo, Preferences, PreferencesMap};
const APP_INFO: AppInfo = AppInfo {
name: "preferences",
author: "Rust language community",
};
const TEST_PREFIX: &'static str = "tests/module";
const TEST_PREFIX: &str = "tests/module";
fn gen_test_name(name: &str) -> String {
TEST_PREFIX.to_owned() + "/" + name
}
Expand Down

0 comments on commit 67ba5dc

Please sign in to comment.