From 0c64c2405ca8c72718565aff411b37fde5a144f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bernier?= Date: Thu, 7 Nov 2024 18:40:02 -0500 Subject: [PATCH] Bring the CI config to 2024 (#14) * Bring the CI config to 2024 * Fix doc warnings --- .github/workflows/base62.yml | 102 +++++++++++++++++++++-------------- src/lib.rs | 28 +++++----- 2 files changed, 76 insertions(+), 54 deletions(-) diff --git a/.github/workflows/base62.yml b/.github/workflows/base62.yml index b35405b..58b2a54 100644 --- a/.github/workflows/base62.yml +++ b/.github/workflows/base62.yml @@ -1,64 +1,86 @@ -on: [push, pull_request] - name: ci +on: + push: + pull_request: + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: "-D warnings" + jobs: check: name: Check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: check + - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + - name: Run cargo check + run: cargo check --all-targets --all-features test: name: Test Suite - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + rust: [stable] + include: + - os: ubuntu-latest + rust: nightly + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: test + toolchain: ${{ matrix.rust }} + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + - name: Run tests + run: cargo test --all-targets --all-features + - name: Run doc tests + run: cargo test --doc fmt: name: Rustfmt runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - run: rustup component add rustfmt - - uses: actions-rs/cargo@v1 + - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable with: - command: fmt - args: --all -- --check + components: rustfmt + - name: Check formatting + run: cargo fmt --all -- --check clippy: name: Clippy runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - run: rustup component add clippy - - uses: actions-rs/cargo@v1 + - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable with: - command: clippy - args: -- -D warnings + components: clippy + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + - name: Run clippy + run: cargo clippy --all-targets --all-features + + docs: + name: Docs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + - name: Check documentation + env: + RUSTDOCFLAGS: "-D warnings" + run: cargo doc --no-deps --document-private-items diff --git a/src/lib.rs b/src/lib.rs index 03c7d48..5effb56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ /*! -`base62` is a `no_std` crate (requires [`alloc`](alloc)) that has six functions for +`base62` is a `no_std` crate (requires [`alloc`]) that has six functions for encoding to and decoding from [base62](https://en.wikipedia.org/wiki/Base62). [![Build status](https://github.com/fbernier/base62/workflows/ci/badge.svg)](https://github.com/fbernier/base62/actions) @@ -33,11 +33,11 @@ const BASE_TO_19: u128 = BASE_TO_18 * BASE as u128; const BASE_TO_20: u128 = BASE_TO_19 * BASE as u128; const BASE_TO_21: u128 = BASE_TO_20 * BASE as u128; -/// Indicates the cause of a decoding failure in [`decode`](crate::decode) or -/// [`decode_alternative`](crate::decode_alternative). +/// Indicates the cause of a decoding failure in [`decode`] or +/// [`decode_alternative`]. #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub enum DecodeError { - /// The decoded number cannot fit into a [`u128`](core::primitive::u128). + /// The decoded number cannot fit into a [`u128`]. ArithmeticOverflow, /// The encoded input is an empty string. @@ -448,11 +448,11 @@ macro_rules! internal_decoder_fn { internal_decoder_fn!(_decode, 0, 10, 36); internal_decoder_fn!(_decode_alternative, 0, 36, 10); -/// Decodes a base62 byte slice or an equivalent, like a [`String`](alloc::string::String), +/// Decodes a base62 byte slice or an equivalent, like a [`String`], /// using the standard digit ordering (0 to 9, then A to Z, then a to z). /// -/// Returns a [`Result`](core::result::Result) containing the decoded -/// [`u128`](core::primitive::u128) or a [`DecodeError`](crate::DecodeError). +/// Returns a [`Result`] containing the decoded +/// [`u128`] or a [`DecodeError`]. /// /// # Examples /// @@ -467,12 +467,12 @@ pub fn decode>(input: T) -> Result { _decode(input.as_ref()) } -/// Decodes a base62 byte slice or an equivalent, like a [`String`](alloc::string::String), +/// Decodes a base62 byte slice or an equivalent, like a [`String`], /// using the alternative digit ordering (0 to 9, then a to z, then A to Z) with lowercase /// letters before uppercase letters. /// -/// Returns a [`Result`](core::result::Result) containing the decoded -/// [`u128`](core::primitive::u128) or a [`DecodeError`](crate::DecodeError). +/// Returns a [`Result`] containing the decoded +/// [`u128`] or a [`DecodeError`]. /// /// # Examples /// @@ -624,7 +624,7 @@ internal_encoder_fn!(_encode_alternative_buf, b'0', b'a', b'A'); /// Encodes an unsigned integer into base62, using the standard digit ordering /// (0 to 9, then A to Z, then a to z), and returns the resulting -/// [`String`](alloc::string::String). +/// [`String`]. /// /// # Example /// @@ -649,7 +649,7 @@ pub fn encode>(num: T) -> String { /// Encodes an unsigned integer into base62, using the standard digit ordering /// (0 to 9, then A to Z, then a to z), and then appends it onto the end of the given -/// [`String`](alloc::string::String). +/// [`String`]. /// /// # Example /// @@ -751,7 +751,7 @@ pub fn encode_alternative_bytes>( /// Encodes an unsigned integer into base62, using the alternative digit ordering /// (0 to 9, then a to z, then A to Z) with lowercase letters before uppercase letters, -/// and returns the resulting [`String`](alloc::string::String). +/// and returns the resulting [`String`]. /// /// # Example /// @@ -776,7 +776,7 @@ pub fn encode_alternative>(num: T) -> String { /// Encodes an unsigned integer into base62, using the alternative digit ordering /// (0 to 9, then a to z, then A to Z) with lowercase letters before uppercase letters, and -/// then appends it onto the end of the given [`String`](alloc::string::String). +/// then appends it onto the end of the given [`String`]. /// /// # Example ///