From e9a37a75c35acd6f615437b3b42ea6cdbab1f0bc Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Fri, 21 Nov 2025 18:59:35 +0100 Subject: [PATCH 1/8] Added rust-version to Cargo.toml --- Cargo.toml | 1 + src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ea3680d..402faa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" description = "A fast thread-safe single producer-single consumer ring buffer" repository = "https://github.com/Mallets/ringbuffer-spsc" license = "EPL-2.0 OR Apache-2.0" +rust-version = "1.79" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/lib.rs b/src/lib.rs index 5f4b907..e220870 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,10 +56,10 @@ pub fn ringbuffer(capacity: usize) -> (RingBufferWriter, RingBufferReader< .into_boxed_slice(); let rb = Arc::new(RingBuffer { - // Keep + // Keep the pointer to the boxed slice ptr: Box::into_raw(v), // Since capacity is a power of two, capacity-1 is a mask covering N elements overflowing when N elements have been added. - // Indexes are left growing indefinetely and naturally wraps around once the index increment reaches usize::MAX. + // Indexes are left growing indefinetely and naturally wrap around once the index increment reaches usize::MAX. mask: capacity - 1, idx_r: CachePadded::new(AtomicUsize::new(0)), idx_w: CachePadded::new(AtomicUsize::new(0)), From b85f2217e3ba89b13b505d06894123d38c364893 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Fri, 21 Nov 2025 19:05:57 +0100 Subject: [PATCH 2/8] Add .github --- .github/workflows/ci.yaml | 241 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..160cd46 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,241 @@ +name: CI + +on: + push: + branches: ["**"] + pull_request: + branches: ["**"] + +jobs: + matrix: + + + check_rust: + needs: determine-runner + name: Check zenoh using Rust 1.75 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ${{ fromJSON(needs.determine-runner.outputs.runner) }} + + steps: + - name: Clone this repository + uses: actions/checkout@v4 + + - name: Update Rust 1.75.0 toolchain + run: rustup update 1.75.0 + + - name: Check zenoh with rust 1.75.0 + run: cargo +1.75.0 check --release --bins --lib + + - name: Install latest cargo-machete + uses: taiki-e/install-action@cargo-machete + + check: + needs: determine-runner + name: Lints and doc tests on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ${{ fromJSON(needs.determine-runner.outputs.runner) }} + + steps: + - name: Clone this repository + uses: actions/checkout@v4 + + - name: Update Stable Rust toolchain + run: rustup update stable + + - name: Make sure necessary tools are installed + run: | + rustup component add clippy --toolchain stable + rustup component add rustfmt --toolchain nightly + + - name: Setup rust-cache + uses: Swatinem/rust-cache@v2 + with: + cache-bin: false + + - name: Clippy all features + if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }} + run: cargo +stable clippy --all-targets --all-features -- --deny warnings + + - name: Install generic no_std target + # Generic no_std target architecture is x86_64-unknown-none + run: rustup target add x86_64-unknown-none + + - name: Perform no_std checks + run: cargo check --bin nostd_check --target x86_64-unknown-none --manifest-path ci/nostd-check/Cargo.toml + + - name: Run doctests + run: cargo test --doc + + - name: Check licenses + run: cargo deny check licenses + + - name: Check unused dependencies + run: cargo machete + + - name: Check SemVer Compatibility + run: cargo +stable semver-checks --verbose --default-features --package zenoh --release-type ${{ env.CARGO_SEMVER_CHECKS_RELEASE_TYPE }} --baseline-version ${{ env.CARGO_SEMVER_CHECKS_BASELINE_VERSION }} + + - name: Check TOML formatting + if: ${{ !contains(matrix.os, 'windows') }} + run: taplo fmt --check --diff + + test: + needs: determine-runner + name: Unit tests on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ${{ fromJSON(needs.determine-runner.outputs.runner) }} + + steps: + - name: Clone this repository + uses: actions/checkout@v4 + + - name: Install latest Rust toolchain + run: rustup show + + - name: Setup rust-cache + uses: Swatinem/rust-cache@v2 + with: + cache-bin: false + + - name: Set rustflags + if: ${{ matrix.os == 'windows-latest' }} + shell: bash + run: | + echo "RUSTFLAGS=-Clink-arg=/DEBUG:NONE" >> $GITHUB_ENV + + - name: Install latest nextest + uses: taiki-e/install-action@nextest + + - name: Run tests stable (sudo macos) + if: ${{ matrix.os == 'macos-latest' }} + run: sudo cargo nextest run -p zenoh -F internal_config + + - name: Run tests stable + if: ${{ matrix.os != 'macos-latest' }} + run: cargo nextest run -p zenoh -F internal_config + + - name: Run tests with unstable (sudo macos) + if: ${{ matrix.os == 'macos-latest' }} + run: sudo cargo nextest run -F test -F internal_config --exclude zenoh-examples --exclude zenoh-plugin-example --workspace + + - name: Run tests with unstable + if: ${{ matrix.os != 'macos-latest' }} + run: cargo nextest run -F test -F internal_config --exclude zenoh-examples --exclude zenoh-plugin-example --workspace + + - name: Rename junit test report (sudo macos) + if: ${{ matrix.os == 'macos-latest' }} + run: sudo mv target/nextest/default/junit.xml target/nextest/default/tests.junit.xml + + - name: Rename junit test report + if: ${{ matrix.os != 'macos-latest' }} + run: mv target/nextest/default/junit.xml target/nextest/default/tests.junit.xml + + - name: Run tests with SHM (sudo macos) + if: ${{ matrix.os == 'macos-latest' }} + run: sudo cargo nextest run -F test -F shared-memory -F unstable -F internal_config -E 'not (test(test_default_features))' --exclude zenoh-examples --exclude zenoh-plugin-example --workspace + env: + RUST_BACKTRACE: 1 + + - name: Run tests with SHM + if: ${{ matrix.os == 'windows-latest' }} + run: cargo nextest run -F test -F shared-memory -F unstable -F internal_config -E 'not (test(test_default_features))' --exclude zenoh-examples --exclude zenoh-plugin-example --workspace + + - name: Rename junit test report (sudo macos) + if: ${{ matrix.os == 'macos-latest' }} + run: sudo mv target/nextest/default/junit.xml target/nextest/default/tests-shm.junit.xml + + - name: Rename junit test report + if: ${{ matrix.os == 'windows-latest' }} + run: mv target/nextest/default/junit.xml target/nextest/default/tests-shm.junit.xml + + - name: Run tests with SHM + unixpipe + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + sudo prlimit --memlock=unlimited --pid=$$ + cargo nextest run -F test -F shared-memory -F unstable -F internal_config -F transport_unixpipe -E 'not (test(test_default_features))' --exclude zenoh-examples --exclude zenoh-plugin-example --workspace + + - name: Rename junit test report + if: ${{ matrix.os == 'ubuntu-latest' }} + run: mv target/nextest/default/junit.xml target/nextest/default/tests-shm-unixpipe.junit.xml + + - name: Check for feature leaks + if: ${{ matrix.os == 'ubuntu-latest' }} + run: cargo nextest run -p zenohd --no-default-features + + - name: Rename junit test report + if: ${{ matrix.os == 'ubuntu-latest' }} + run: mv target/nextest/default/junit.xml target/nextest/default/tests-feature-leaks.junit.xml + + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + valgrind: + name: Memory leak checks + runs-on: ubuntu-latest + needs: check + steps: + - name: Clone this repository + uses: actions/checkout@v4 + + - name: Install latest Rust toolchain + run: rustup show + + - name: Install valgrind + uses: taiki-e/install-action@valgrind + + - uses: Swatinem/rust-cache@v2 + with: + cache-bin: false + + - name: Run memory leaks check + run: ci/valgrind-check/run.sh + shell: bash + + typos: + name: Typos Check + runs-on: ubuntu-latest + steps: + - name: Clone this repository + uses: actions/checkout@v4 + + - name: Check spelling + uses: crate-ci/typos@master + + markdown_lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DavidAnson/markdownlint-cli2-action@v18 + with: + config: '.markdownlint.yaml' + globs: '**/README.md' + + doc: + name: Generate documentation + runs-on: ubuntu-latest + steps: + - name: Clone this repository + uses: actions/checkout@v4 + + # Use a similar command than docs.rs build: rustdoc with nightly toolchain + - name: Install Rust toolchain nightly for docs gen + run: rustup toolchain install nightly + + - name: Run rustdoc using Nightly Rust and Zenoh unstable + # NOTE: force 'unstable' feature for doc generation, as forced for docs.rs build in zenoh/Cargo.toml + run: | + cargo +nightly rustdoc --manifest-path ./zenoh/Cargo.toml --lib --features "shared-memory unstable" -j3 \ + -Z rustdoc-map -Z unstable-options -Z rustdoc-scrape-examples \ + --config build.rustdocflags='["--cfg", "docsrs", "-Z", "unstable-options", "--emit=invocation-specific", "--cap-lints", "warn", "--extern-html-root-takes-precedence"]' From 561ae0e7dc2c64c4ed360f2cf0862183b184b255 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Sat, 22 Nov 2025 11:37:29 +0100 Subject: [PATCH 3/8] Github CI workflow --- .github/workflows/ci.yaml | 228 ++++---------------------------------- 1 file changed, 23 insertions(+), 205 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 160cd46..4f3a77f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,235 +7,53 @@ on: branches: ["**"] jobs: - matrix: - - - check_rust: - needs: determine-runner - name: Check zenoh using Rust 1.75 - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: ${{ fromJSON(needs.determine-runner.outputs.runner) }} - - steps: - - name: Clone this repository - uses: actions/checkout@v4 - - - name: Update Rust 1.75.0 toolchain - run: rustup update 1.75.0 - - - name: Check zenoh with rust 1.75.0 - run: cargo +1.75.0 check --release --bins --lib - - - name: Install latest cargo-machete - uses: taiki-e/install-action@cargo-machete - check: - needs: determine-runner - name: Lints and doc tests on ${{ matrix.os }} + name: Check (${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - os: ${{ fromJSON(needs.determine-runner.outputs.runner) }} - + os: [ubuntu-latest, windows-latest, macos-latest] steps: - - name: Clone this repository + - name: Checkout uses: actions/checkout@v4 - - name: Update Stable Rust toolchain + - name: Install Rust toolchain run: rustup update stable - name: Make sure necessary tools are installed run: | rustup component add clippy --toolchain stable - rustup component add rustfmt --toolchain nightly - - - name: Setup rust-cache - uses: Swatinem/rust-cache@v2 - with: - cache-bin: false - - - name: Clippy all features - if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }} - run: cargo +stable clippy --all-targets --all-features -- --deny warnings - - - name: Install generic no_std target - # Generic no_std target architecture is x86_64-unknown-none - run: rustup target add x86_64-unknown-none - - - name: Perform no_std checks - run: cargo check --bin nostd_check --target x86_64-unknown-none --manifest-path ci/nostd-check/Cargo.toml - - - name: Run doctests - run: cargo test --doc - - - name: Check licenses - run: cargo deny check licenses - - - name: Check unused dependencies - run: cargo machete - - - name: Check SemVer Compatibility - run: cargo +stable semver-checks --verbose --default-features --package zenoh --release-type ${{ env.CARGO_SEMVER_CHECKS_RELEASE_TYPE }} --baseline-version ${{ env.CARGO_SEMVER_CHECKS_BASELINE_VERSION }} - - - name: Check TOML formatting - if: ${{ !contains(matrix.os, 'windows') }} - run: taplo fmt --check --diff - - test: - needs: determine-runner - name: Unit tests on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: ${{ fromJSON(needs.determine-runner.outputs.runner) }} - - steps: - - name: Clone this repository - uses: actions/checkout@v4 - - - name: Install latest Rust toolchain - run: rustup show + rustup component add rustfmt --toolchain stable - name: Setup rust-cache uses: Swatinem/rust-cache@v2 with: cache-bin: false - - name: Set rustflags - if: ${{ matrix.os == 'windows-latest' }} - shell: bash - run: | - echo "RUSTFLAGS=-Clink-arg=/DEBUG:NONE" >> $GITHUB_ENV - - - name: Install latest nextest - uses: taiki-e/install-action@nextest - - - name: Run tests stable (sudo macos) - if: ${{ matrix.os == 'macos-latest' }} - run: sudo cargo nextest run -p zenoh -F internal_config - - - name: Run tests stable - if: ${{ matrix.os != 'macos-latest' }} - run: cargo nextest run -p zenoh -F internal_config - - - name: Run tests with unstable (sudo macos) - if: ${{ matrix.os == 'macos-latest' }} - run: sudo cargo nextest run -F test -F internal_config --exclude zenoh-examples --exclude zenoh-plugin-example --workspace - - - name: Run tests with unstable - if: ${{ matrix.os != 'macos-latest' }} - run: cargo nextest run -F test -F internal_config --exclude zenoh-examples --exclude zenoh-plugin-example --workspace - - - name: Rename junit test report (sudo macos) - if: ${{ matrix.os == 'macos-latest' }} - run: sudo mv target/nextest/default/junit.xml target/nextest/default/tests.junit.xml - - - name: Rename junit test report - if: ${{ matrix.os != 'macos-latest' }} - run: mv target/nextest/default/junit.xml target/nextest/default/tests.junit.xml - - - name: Run tests with SHM (sudo macos) - if: ${{ matrix.os == 'macos-latest' }} - run: sudo cargo nextest run -F test -F shared-memory -F unstable -F internal_config -E 'not (test(test_default_features))' --exclude zenoh-examples --exclude zenoh-plugin-example --workspace - env: - RUST_BACKTRACE: 1 - - - name: Run tests with SHM - if: ${{ matrix.os == 'windows-latest' }} - run: cargo nextest run -F test -F shared-memory -F unstable -F internal_config -E 'not (test(test_default_features))' --exclude zenoh-examples --exclude zenoh-plugin-example --workspace - - - name: Rename junit test report (sudo macos) - if: ${{ matrix.os == 'macos-latest' }} - run: sudo mv target/nextest/default/junit.xml target/nextest/default/tests-shm.junit.xml - - - name: Rename junit test report - if: ${{ matrix.os == 'windows-latest' }} - run: mv target/nextest/default/junit.xml target/nextest/default/tests-shm.junit.xml - - - name: Run tests with SHM + unixpipe - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - sudo prlimit --memlock=unlimited --pid=$$ - cargo nextest run -F test -F shared-memory -F unstable -F internal_config -F transport_unixpipe -E 'not (test(test_default_features))' --exclude zenoh-examples --exclude zenoh-plugin-example --workspace - - - name: Rename junit test report - if: ${{ matrix.os == 'ubuntu-latest' }} - run: mv target/nextest/default/junit.xml target/nextest/default/tests-shm-unixpipe.junit.xml - - - name: Check for feature leaks - if: ${{ matrix.os == 'ubuntu-latest' }} - run: cargo nextest run -p zenohd --no-default-features - - - name: Rename junit test report - if: ${{ matrix.os == 'ubuntu-latest' }} - run: mv target/nextest/default/junit.xml target/nextest/default/tests-feature-leaks.junit.xml - - - name: Upload test results to Codecov - if: ${{ !cancelled() }} - uses: codecov/test-results-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} - - valgrind: - name: Memory leak checks - runs-on: ubuntu-latest - needs: check - steps: - - name: Clone this repository - uses: actions/checkout@v4 + - name: Install latest cargo-machete + uses: taiki-e/install-action@cargo-machete - - name: Install latest Rust toolchain - run: rustup show + - name: Install latest taplo + uses: taiki-e/install-action@taplo - - name: Install valgrind - uses: taiki-e/install-action@valgrind + - name: Run cargo clippy + run: cargo clippy --all-targets --all-features -- -D warnings - - uses: Swatinem/rust-cache@v2 - with: - cache-bin: false + - name: Run cargo test + run: cargo test --all-features - - name: Run memory leaks check - run: ci/valgrind-check/run.sh - shell: bash + - name: Run cargo test --doc + run: cargo test --all-features --doc - typos: - name: Typos Check - runs-on: ubuntu-latest - steps: - - name: Clone this repository - uses: actions/checkout@v4 + - name: Run cargo doc + run: cargo doc --no-deps --all-features - - name: Check spelling - uses: crate-ci/typos@master - - markdown_lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: DavidAnson/markdownlint-cli2-action@v18 - with: - config: '.markdownlint.yaml' - globs: '**/README.md' - - doc: - name: Generate documentation - runs-on: ubuntu-latest - steps: - - name: Clone this repository - uses: actions/checkout@v4 + - name: Check unused dependencies (cargo machete) + run: cargo machete - # Use a similar command than docs.rs build: rustdoc with nightly toolchain - - name: Install Rust toolchain nightly for docs gen - run: rustup toolchain install nightly + - name: Check formatting (cargo fmt) + run: cargo fmt --all --check - - name: Run rustdoc using Nightly Rust and Zenoh unstable - # NOTE: force 'unstable' feature for doc generation, as forced for docs.rs build in zenoh/Cargo.toml - run: | - cargo +nightly rustdoc --manifest-path ./zenoh/Cargo.toml --lib --features "shared-memory unstable" -j3 \ - -Z rustdoc-map -Z unstable-options -Z rustdoc-scrape-examples \ - --config build.rustdocflags='["--cfg", "docsrs", "-Z", "unstable-options", "--emit=invocation-specific", "--cap-lints", "warn", "--extern-html-root-takes-precedence"]' + - name: Check TOML formatting (taplo) + run: taplo fmt --check --diff From 3cbc340960732016c4c0911dfae8bf7a4e1d2472 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Sat, 22 Nov 2025 11:38:51 +0100 Subject: [PATCH 4/8] ci: fix clippy --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index e220870..78ccb35 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,6 +86,7 @@ struct RingBuffer { } impl RingBuffer { + #[allow(clippy::mut_from_ref)] unsafe fn get_unchecked_mut(&self, idx: usize) -> &mut MaybeUninit { unsafe { (&mut (*self.ptr)).get_unchecked_mut(idx & self.mask) } } From 67e1853e0344444a1db00507ff76409a71e6cc76 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Sat, 22 Nov 2025 11:47:18 +0100 Subject: [PATCH 5/8] ci: rework GitHub workflow --- .github/workflows/ci.yaml | 85 ++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4f3a77f..0d57774 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,9 +22,54 @@ jobs: run: rustup update stable - name: Make sure necessary tools are installed - run: | - rustup component add clippy --toolchain stable - rustup component add rustfmt --toolchain stable + run: rustup component add clippy --toolchain stable + + - name: Setup rust-cache + uses: Swatinem/rust-cache@v2 + with: + cache-bin: false + + - name: Run cargo clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + - name: Check formatting (cargo fmt) + run: cargo fmt --all --check + + test: + name: Test (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Rust toolchain + run: rustup update stable + + - name: Setup rust-cache + uses: Swatinem/rust-cache@v2 + with: + cache-bin: false + + - name: Run cargo test + run: cargo test --all-features + + toml: + name: Format (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Rust toolchain + run: rustup update stable - name: Setup rust-cache uses: Swatinem/rust-cache@v2 @@ -37,11 +82,30 @@ jobs: - name: Install latest taplo uses: taiki-e/install-action@taplo - - name: Run cargo clippy - run: cargo clippy --all-targets --all-features -- -D warnings + - name: Check unused dependencies (cargo machete) + run: cargo machete - - name: Run cargo test - run: cargo test --all-features + - name: Check TOML formatting (taplo) + run: taplo fmt --check --diff + + docs: + name: Docs (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Rust toolchain + run: rustup update stable + + - name: Setup rust-cache + uses: Swatinem/rust-cache@v2 + with: + cache-bin: false - name: Run cargo test --doc run: cargo test --all-features --doc @@ -49,11 +113,4 @@ jobs: - name: Run cargo doc run: cargo doc --no-deps --all-features - - name: Check unused dependencies (cargo machete) - run: cargo machete - - name: Check formatting (cargo fmt) - run: cargo fmt --all --check - - - name: Check TOML formatting (taplo) - run: taplo fmt --check --diff From baf562585a1606999ea77320d2184ca59c2df8b2 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Sat, 22 Nov 2025 11:55:35 +0100 Subject: [PATCH 6/8] ci: fix test --- .github/workflows/ci.yaml | 27 --------------------------- src/lib.rs | 5 +++-- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0d57774..6a65bac 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -87,30 +87,3 @@ jobs: - name: Check TOML formatting (taplo) run: taplo fmt --check --diff - - docs: - name: Docs (${{ matrix.os }}) - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install Rust toolchain - run: rustup update stable - - - name: Setup rust-cache - uses: Swatinem/rust-cache@v2 - with: - cache-bin: false - - - name: Run cargo test --doc - run: cargo test --all-features --doc - - - name: Run cargo doc - run: cargo doc --no-deps --all-features - - diff --git a/src/lib.rs b/src/lib.rs index 78ccb35..185fa61 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,10 +5,10 @@ //! //! # Example //! ```rust -//! use ringbuffer_spsc::RingBuffer; +//! use ringbuffer_spsc::ringbuffer; //! //! const N: usize = 1_000_000; -//! let (mut tx, mut rx) = RingBuffer::::new(16); +//! let (mut tx, mut rx) = ringbuffer::(16); //! //! let p = std::thread::spawn(move || { //! let mut current: usize = 0; @@ -49,6 +49,7 @@ use crossbeam_utils::CachePadded; /// Panic: it panics if capacity is not a power of 2. pub fn ringbuffer(capacity: usize) -> (RingBufferWriter, RingBufferReader) { assert!(capacity.is_power_of_two(), "Capacity must be a power of 2"); + // Inner container let v = (0..capacity) .map(|_| MaybeUninit::uninit()) From 50db03318410076ca738ef28185e9fd0daa58369 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Sat, 22 Nov 2025 11:57:12 +0100 Subject: [PATCH 7/8] ci: do not run taplo on Windows --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6a65bac..00b02bb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -86,4 +86,5 @@ jobs: run: cargo machete - name: Check TOML formatting (taplo) + if: ${{ !contains(matrix.os, 'windows') }} run: taplo fmt --check --diff From d5ab46b2a5430ac607387d1c3d517196aeb81ba0 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Sat, 22 Nov 2025 12:07:57 +0100 Subject: [PATCH 8/8] Add badges to README --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0354847..6ae9cc1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +[![CI](https://github.com/Mallets/ringbuffer-spsc/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Mallets/ringbuffer-spsc/actions?query=workflow%3ACI+branch%3Amain++) +[![docs.rs](https://img.shields.io/docsrs/ringbuffer-spsc)](https://docs.rs/ringbuffer-spsc/latest/ringbuffer_spsc/) +[![License](https://img.shields.io/badge/License-EPL%202.0-blue)](https://choosealicense.com/licenses/epl-2.0/) +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) + # ringbuffer-spsc A fast single-producer single-consumer ring buffer. @@ -48,7 +53,7 @@ fn main() { Tests run on an Apple M4, 32 GB of RAM. ```sh -$ cargo run --release --example throughput +cargo run --release --example throughput ``` Provides `~520M elem/s` of sustained throughput. @@ -65,4 +70,4 @@ Provides `~520M elem/s` of sustained throughput. 520486274 elem/s 522570696 elem/s ... -``` \ No newline at end of file +```