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

Bring the CI config to 2024 #14

Merged
merged 2 commits into from
Nov 7, 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
102 changes: 62 additions & 40 deletions .github/workflows/base62.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 14 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
///
Expand All @@ -467,12 +467,12 @@ pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<u128, DecodeError> {
_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
///
Expand Down Expand Up @@ -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
///
Expand All @@ -649,7 +649,7 @@ pub fn encode<T: Into<u128>>(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
///
Expand Down Expand Up @@ -751,7 +751,7 @@ pub fn encode_alternative_bytes<T: Into<u128>>(

/// 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
///
Expand All @@ -776,7 +776,7 @@ pub fn encode_alternative<T: Into<u128>>(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
///
Expand Down