name: Rust

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  fmt:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
    - name: Check formatting
      run: cargo fmt --check

  clippy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
    - name: Clippy
      run: cargo clippy --all-targets --all-features -- -D warnings

  doc:
    runs-on: ubuntu-latest
    env:
      RUSTDOCFLAGS: -D warnings
    steps:
    - uses: actions/checkout@v6
    - name: Build docs
      run: cargo doc --no-deps --all-features

  test:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        rust: [stable, "1.85"]
    runs-on: ${{ matrix.os }}
    continue-on-error: ${{ matrix.os == 'windows-latest' }}
    steps:
    - uses: actions/checkout@v6
    - name: Install Rust ${{ matrix.rust }}
      run: rustup toolchain install ${{ matrix.rust }} --profile minimal && rustup default ${{ matrix.rust }}
    - name: Test (all features)
      run: cargo test --all-features --verbose
