Skip to content
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
184 changes: 149 additions & 35 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,181 @@
name: Rust CI
name: CI

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

permissions:
contents: read

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -Dwarnings

jobs:
build-and-docs:
# Test on stable with all feature combinations
stable:
name: Stable (${{ matrix.name }})
runs-on: ubuntu-latest

timeout-minutes: 45
strategy:
fail-fast: false
matrix:
include:
- name: "no_std"
flags: "--no-default-features"
- name: "alloc"
flags: "--no-default-features --features alloc"
- name: "std"
flags: "--features std"
- name: "default"
flags: ""
steps:
# Checkout code
- uses: actions/checkout@v4

# Cache Cargo registry and git sources
- name: Cache Cargo registry
uses: actions/cache@v3
- name: Cache Cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-registry-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: cargo-registry-${{ runner.os }}-
target
key: ${{ runner.os }}-cargo-stable-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.name }}
restore-keys: |
${{ runner.os }}-cargo-stable-${{ hashFiles('**/Cargo.lock') }}-
${{ runner.os }}-cargo-stable-
${{ runner.os }}-cargo-

- uses: dtolnay/rust-toolchain@stable

# Cache Cargo build artifacts
- name: Cache Cargo target directory
uses: actions/cache@v3
- name: Build
run: cargo build ${{ matrix.flags }} --verbose

- name: Test
run: cargo test ${{ matrix.flags }} --verbose

# Test on nightly with nightly feature
nightly:
name: Nightly (${{ matrix.name }})
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
include:
- name: "no_std"
flags: "--no-default-features"
- name: "alloc"
flags: "--no-default-features --features alloc"
- name: "std+nightly"
flags: "--features std,nightly"
- name: "all-features"
flags: "--all-features"
steps:
- uses: actions/checkout@v4

- name: Cache Cargo
uses: actions/cache@v4
with:
path: target
key: cargo-target-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: cargo-target-${{ runner.os }}-
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-nightly-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.name }}
restore-keys: |
${{ runner.os }}-cargo-nightly-${{ hashFiles('**/Cargo.lock') }}-
${{ runner.os }}-cargo-nightly-
${{ runner.os }}-cargo-

- uses: dtolnay/rust-toolchain@nightly

- name: Build
run: cargo build ${{ matrix.flags }} --verbose

- name: Test
run: cargo test ${{ matrix.flags }} --verbose

# Clippy linting on all features
clippy:
name: Clippy
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4

# Install stable Rust for CI
- name: Install stable Rust
uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy

# Lint (excluding nightly feature)
- name: Clippy check
run: cargo clippy --all-targets --features std -- -D warnings
- name: Clippy (all features)
run: cargo clippy --all-targets --all-features -- -Dclippy::all -Dclippy::pedantic -Dclippy::nursery

# Rustfmt check
fmt:
name: Rustfmt
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4

# Run tests (excluding nightly feature)
- name: Run tests
run: cargo test --features std --verbose
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

# Build crate (excluding nightly feature)
- name: Build crate
run: cargo build --features std --verbose
- name: Check formatting
run: cargo fmt --all -- --check

- name: Build with no-default-features
run: cargo build --no-default-features --verbose
# Documentation
doc:
name: Documentation
runs-on: ubuntu-latest
timeout-minutes: 45
env:
RUSTDOCFLAGS: -Dwarnings
steps:
- uses: actions/checkout@v4

# --- Docs.rs using nightly ---
- name: Install nightly Rust
uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@nightly

- name: Install cargo-docs-rs
uses: dtolnay/install@cargo-docs-rs
- uses: dtolnay/install@cargo-docs-rs

- name: Build docs.rs documentation
run: cargo docs-rs
run: cargo docs-rs

- name: Build docs (all features)
run: cargo doc --no-deps --all-features

# Minimal versions
minimal:
name: Minimal versions
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@nightly

- name: Generate minimal lockfile
run: cargo generate-lockfile -Z minimal-versions

- name: Check with minimal versions
run: cargo check --locked --all-features

# Miri for undefined behavior detection
miri:
name: Miri
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@miri

- name: Setup Miri
run: cargo miri setup

- name: Test with Miri (all features)
run: cargo miri test --all-features
env:
MIRIFLAGS: -Zmiri-strict-provenance
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stack_collections"
version = "0.2.0"
version = "0.3.0"
edition = "2024"
authors = ["Kyle Thapar <kylethapar2007@outlook.com>"]
description = "Stack-allocated collections for Rust"
Expand All @@ -18,5 +18,6 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
std = []
std = ["alloc"]
alloc = []
nightly = []
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
stack_collections = "0.2.0"
stack_collections = "0.3.0"
```

### StackString Example
Expand All @@ -32,16 +32,16 @@ stack_collections = "0.2.0"
use stack_collections::StackString;

fn main() {
let mut s = StackString::<32>::new();
s.push_str("Hello, ");
s.push_str("world!");
let mut stack_string = StackString::<32>::new();
stack_string.push_str("Hello, ");
stack_string.push_str("world!");

println!("String: {}", s);
println!("Length: {}", s.len());
println!("Capacity: {}", s.capacity());
println!("String: {}", stack_string);
println!("Length: {}", stack_string.len());
println!("Capacity: {}", stack_string.capacity());

// Pop characters
while let Some(c) = s.try_pop() {
while let Some(c) = stack_string.try_pop() {
println!("Popped: {}", c);
}
}
Expand All @@ -53,17 +53,17 @@ fn main() {
use stack_collections::StackVec;

fn main() {
let mut v = StackVec::<i32, 8>::new();
let mut vec = StackVec::<i32, 8>::new();

for i in 1..=5 {
v.push(i);
vec.push(i);
}

println!("Vector: {:?}", v);
println!("Sum: {}", v.iter().sum::<i32>());
println!("Vector: {:?}", vec);
println!("Sum: {}", vec.iter().sum::<i32>());

v.retain(|x| *x % 2 == 0);
println!("Even numbers: {:?}", v);
vec.retain(|x| *x < 4);
println!("Numbers less than 4: {:?}", vec);
}
```

Expand Down Expand Up @@ -115,8 +115,8 @@ undefined behavior even when capacity is exceeded (operations will panic or retu

Licensed under either of:

- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)

at your option.

Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 120
Loading