async-deferred 0.4.0

A lightweight utility for spawning async tasks with fire-and-forget semantics and deferred result retrieval.
Documentation
name: CI

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

permissions:
  contents: read

# Cancel a run when a newer commit is pushed to the same branch or pull request.
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    name: Test (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      - name: All features
        run: cargo test --all-features

      # Doctests need the default features, so only the test targets run here.
      - name: Deferred without std (no_std + alloc)
        run: cargo test --no-default-features --features alloc --tests

      - name: StaticDeferred only (no heap)
        run: cargo test --no-default-features --features static-deferred --tests

      - name: std only, without a runtime
        run: cargo test --no-default-features --features std --tests

  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy, rustfmt
      - uses: Swatinem/rust-cache@v2

      - name: Format
        run: cargo fmt --check

      - name: Clippy (all features)
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Clippy (no_std + alloc)
        run: cargo clippy --all-targets --no-default-features --features alloc -- -D warnings

      - name: Clippy (no heap)
        run: cargo clippy --all-targets --no-default-features --features static-deferred -- -D warnings

      - name: Docs
        run: cargo doc --no-deps --all-features
        env:
          RUSTDOCFLAGS: -D warnings

  docs-rs:
    name: docs.rs
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@nightly
      - uses: Swatinem/rust-cache@v2

      # Same settings as docs.rs, which labels each item with the features it needs.
      - name: Docs as on docs.rs
        run: cargo doc --no-deps --all-features
        env:
          RUSTDOCFLAGS: --cfg docsrs -D warnings

  no-std:
    name: no_std (${{ matrix.target }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          # Targets with atomic compare-and-swap support both modes.
          - target: riscv32imac-unknown-none-elf # e.g. ESP32-C6
            cas: true
          - target: thumbv7em-none-eabihf # e.g. STM32F4, nRF52
            cas: true
          # Without it, only `StaticDeferred` works.
          - target: riscv32imc-unknown-none-elf # e.g. ESP32-C3
            cas: false
          - target: thumbv6m-none-eabi # e.g. RP2040
            cas: false
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v2

      - name: Deferred (alloc)
        if: matrix.cas
        run: cargo build --no-default-features --features alloc --target ${{ matrix.target }}

      - name: Deferred reports a clear error
        if: ${{ !matrix.cas }}
        run: |
          if cargo check --no-default-features --features alloc --target ${{ matrix.target }} 2> build.log; then
            echo "expected the build to fail without atomic compare-and-swap"
            exit 1
          fi
          grep -q "needs atomic compare-and-swap" build.log

      - name: StaticDeferred (no heap)
        run: cargo build --no-default-features --features static-deferred --target ${{ matrix.target }}

  msrv:
    name: MSRV (1.68)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
      - uses: dtolnay/rust-toolchain@1.68

      # Pick the newest dependency versions that still support Rust 1.68.
      - name: Lock dependencies for Rust 1.68
        run: |
          cargo +stable generate-lockfile
          # Cargo 1.68 only reads lockfile version 3.
          sed -i 's/^version = 4$/version = 3/' Cargo.lock
        env:
          CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS: fallback

      - name: All features
        run: cargo +1.68 check --lib --all-features

      - name: Deferred without std (no_std + alloc)
        run: cargo +1.68 check --lib --no-default-features --features alloc

      - name: StaticDeferred only (no heap)
        run: cargo +1.68 check --lib --no-default-features --features static-deferred