name: Rust

on:
  push: {}
  pull_request: {}

jobs:
  build_test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
        - 1.34.0
        - 1.36.0
        - stable
        - beta
        - nightly
    steps:
    - uses: actions/checkout@v1
    - uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: ${{ matrix.rust }}
        default: true
    - name: Build the crate on minimal version.
      uses: actions-rs/cargo@v1
      with:
        command: build
    - name: Build the crate on 1.36 with features.
      if: matrix.rust != '1.34.0'
      uses: actions-rs/cargo@v1
      with:
        command: build
        # Using `extern crate alloc` is only possible after 1.36
        args: --features=alloc,std,grab_spare_slice
    - name: Test on Stable/Beta
      if: matrix.rust != '1.34.0' && matrix.rust != '1.36.0'
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --features=alloc --features=grab_spare_slice --features=rustc_1_40
    - name: Test on Nightly with All Features
      if: matrix.rust == 'nightly'
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --all-features
