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
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,39 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: rust-script scripts/create-github-release.rs --release-version "${{ steps.version.outputs.new_version }}" --repository "${{ github.repository }}"

# === DEPLOY DOCUMENTATION ===
# Generates and deploys Rust API documentation to GitHub Pages after a successful release
deploy-docs:
name: Deploy Rust Documentation
needs: [auto-release, manual-release]
# Run if either release job succeeded (the other will be skipped)
if: |
always() && !cancelled() && (
needs.auto-release.result == 'success' ||
needs.manual-release.result == 'success'
)
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
ref: main

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: Build documentation
run: cargo doc --no-deps

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: target/doc
destination_dir: rust
keep_files: true

# === MANUAL CHANGELOG PR ===
changelog-pr:
name: Create Changelog PR
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "platform-trees"
version = "0.2.0"
edition = "2021"
rust-version = "1.70"
edition = "2024"
rust-version = "1.85"
authors = ["uselesssgoddess", "Linksplatform Team <linksplatformtechnologies@gmail.com>"]
license = "Unlicense"
repository = "https://github.com/linksplatform/trees-rs"
Expand All @@ -20,7 +20,7 @@ path = "src/lib.rs"

[dependencies]
num-traits = "0.2.19"
platform-num = "0.5.0"
platform-num = "0.6.0"

[lints.rust]
unsafe_code = "allow"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Add to your `Cargo.toml`:

```toml
[dependencies]
platform-trees = "0.1.0-beta.1"
platform-trees = "0.2.0"
```

## Usage
Expand Down
19 changes: 19 additions & 0 deletions changelog.d/20260411_000000_edition_2024_audit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
bump: minor
---

### Changed
- Upgrade Rust edition 2021 → 2024 (stable since Rust 1.85, Feb 2025)
- Bump MSRV 1.70 → 1.85 (required for edition 2024)
- Use explicit `unsafe {}` blocks inside `unsafe fn` bodies (edition 2024 requirement)
- Use `&raw mut` / `&raw const` instead of `&mut` / `&` for raw pointer creation (Rust 2024 best practice)

### Added
- Comprehensive doc comments on all 8 public traits and all their methods
- Crate-level documentation with trait summary table and quick-start example
- 4 doc tests covering `LinkType`, `funty()`, `LinkedList`, and crate-level usage
- Automated Rust documentation deployment to GitHub Pages after each release
- Case study document for issue #28 in `docs/case-studies/issue-28/`

### Fixed
- README.md installation example showed `0.1.0-beta.1` instead of current `0.2.0`
104 changes: 104 additions & 0 deletions docs/case-studies/issue-28/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Case Study: Issue #28 — Rust Best Practices Audit

## Issue Summary

**Title:** Double check we don't depend on any non stable features of rust and use all the latest best practices of rust in the code

**Goal:** Comprehensive audit ensuring the crate uses stable Rust, latest editions, up-to-date dependencies, complete documentation, adequate test coverage, and automated documentation generation.

## Requirements Extracted from Issue

1. **No non-stable Rust features** — verify the crate compiles on stable Rust without `#![feature(...)]` gates
2. **Latest dependency versions** — ensure all dependencies are at their newest releases
3. **Latest stable Rust version** — use the current stable toolchain and edition
4. **Documentation in sync with code** — doc comments must accurately describe all public API items
5. **Full feature documentation** — all features present in the code must be documented
6. **Increase test coverage** — add tests for uncovered edge cases and paths
7. **Increase docs coverage** — add doc tests and examples
8. **Automated documentation generation** — set up CI-driven doc deployment to GitHub Pages (following linksplatform/Numbers as the reference)
9. **No tests in `src/` folder** — all tests must reside in the `tests/` directory

## Audit Findings

### 1. Stable Rust Compliance

| Check | Result |
|-------|--------|
| `#![feature(...)]` usage | None found — fully stable |
| `rust-toolchain.toml` | Uses `channel = "stable"` |
| Nightly-only APIs | None used |

**Conclusion:** The crate was already fully stable Rust. No changes needed.

### 2. Edition and MSRV

| Before | After |
|--------|-------|
| Edition 2021 | Edition 2024 |
| MSRV 1.70 | MSRV 1.85 |

**Changes required for edition 2024:**
- Unsafe operations inside `unsafe fn` bodies now require explicit `unsafe {}` blocks ([Rust 2024 migration guide](https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html))
- Raw pointer creation uses `&raw mut` / `&raw const` instead of `&mut` / `&` (clippy `borrow_as_ptr` lint)

### 3. Dependencies

| Dependency | Version | Latest? |
|------------|---------|---------|
| `num-traits` | 0.2.19 | Yes |
| `platform-num` | 0.5.0 | Yes |

### 4. Documentation Sync

**Issues found and fixed:**
- README.md installation example showed `0.1.0-beta.1` instead of `0.2.0`
- No crate-level documentation (`//!` in `lib.rs`)
- No doc comments on any trait or method
- Old `// fixme: #![no_std]` and `// TODO: use human names` comments removed in prior work

**Changes:**
- Added crate-level docs with trait summary table and quick-start example
- Added doc comments to all 8 public traits and all their methods
- Added 4 doc tests (crate-level example, `LinkType` trait, `funty` method, `LinkedList` usage)

### 5. Test Coverage

**Before:** 115 tests (all in `tests/` directory — requirement #9 already met)
- 6 funty compatibility tests
- 42 list tests
- 32 recursive tree tests
- 35 iterative tree tests

**After:** 115 integration tests + 4 doc tests = 119 total tests

The existing test suite already covered all major code paths including edge cases (sequential insert, reverse insert, alternating insert, attach/detach cycles, double rotations, replacement from subtrees, etc.).

### 6. Automated Documentation

Added a `deploy-docs` job to the CI/CD workflow that:
1. Triggers after a successful release (auto or manual)
2. Runs `cargo doc --no-deps` to generate documentation
3. Deploys to the `rust/` subdirectory on `gh-pages` using `peaceiris/actions-gh-pages@v4`

This matches the approach used in [linksplatform/Numbers PR #143](https://github.com/linksplatform/Numbers/pull/143).

## Solution Plan Summary

| Requirement | Solution | Status |
|-------------|----------|--------|
| No non-stable features | Already compliant — verified | Done |
| Latest dependencies | Already at latest — verified | Done |
| Latest edition & MSRV | Edition 2021→2024, MSRV 1.70→1.85 | Done |
| Docs in sync | Fixed README version, added full API docs | Done |
| Feature documentation | All traits and methods documented | Done |
| Test coverage | Already comprehensive; added 4 doc tests | Done |
| Docs coverage | Doc comments + doc tests on all public items | Done |
| Automated docs | `deploy-docs` CI job added | Done |
| No tests in `src/` | Already compliant — verified | Done |

## Related Resources

- [Rust Edition Guide: 2024](https://doc.rust-lang.org/edition-guide/rust-2024/)
- [linksplatform/Numbers PR #143](https://github.com/linksplatform/Numbers/pull/143) — reference implementation for docs CI
- [Size Balanced Tree (Wikipedia)](https://en.wikipedia.org/wiki/Size_Balanced_Tree) — SBT algorithm reference
- [peaceiris/actions-gh-pages](https://github.com/peaceiris/actions-gh-pages) — GitHub Pages deployment action
72 changes: 71 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,74 @@
// fixme: #![no_std]
//! # platform-trees
//!
//! Generic traits for size-balanced binary trees and circular linked lists
//! used throughout the [LinksPlatform](https://github.com/linksplatform) ecosystem.
//!
//! This crate provides trait-based abstractions that allow downstream crates
//! (such as [`doublets`](https://crates.io/crates/doublets)) to implement
//! their own storage-backed trees and lists while reusing the balancing,
//! rotation, and list manipulation logic defined here.
//!
//! ## Traits overview
//!
//! | Trait | Description |
//! |---|---|
//! | [`LinkType`] | Marker trait for unsigned integer types usable as node indices |
//! | [`LinkedList`] | Base doubly-linked list with `get_previous`/`get_next` |
//! | [`AbsoluteLinkedList`] | List with direct `first`/`last`/`size` access |
//! | [`RelativeLinkedList`] | List with head-relative `first`/`last`/`size` |
//! | [`AbsoluteCircularLinkedList`] | Circular list with absolute positioning |
//! | [`RelativeCircularLinkedList`] | Circular list with head-relative positioning |
//! | [`RecursiveSizeBalancedTree`] | Size-balanced BST with rotations and queries |
//! | [`IterativeSizeBalancedTree`] | Iterative `attach`/`detach` over the recursive base |
//!
//! ## Quick start
//!
//! ```rust
//! use platform_trees::{
//! LinkType, LinkedList, AbsoluteLinkedList, AbsoluteCircularLinkedList,
//! };
//!
//! // 1. Define your storage
//! #[derive(Default, Clone, Copy)]
//! struct Node { prev: usize, next: usize }
//!
//! struct MyList {
//! nodes: Vec<Node>,
//! first: usize,
//! last: usize,
//! size: usize,
//! }
//!
//! // 2. Implement the required traits
//! impl LinkedList<usize> for MyList {
//! fn get_previous(&self, el: usize) -> usize { self.nodes[el].prev }
//! fn get_next(&self, el: usize) -> usize { self.nodes[el].next }
//! fn set_previous(&mut self, el: usize, p: usize) { self.nodes[el].prev = p; }
//! fn set_next(&mut self, el: usize, n: usize) { self.nodes[el].next = n; }
//! }
//!
//! impl AbsoluteLinkedList<usize> for MyList {
//! fn get_first(&self) -> usize { self.first }
//! fn get_last(&self) -> usize { self.last }
//! fn get_size(&self) -> usize { self.size }
//! fn set_first(&mut self, el: usize) { self.first = el; }
//! fn set_last(&mut self, el: usize) { self.last = el; }
//! fn set_size(&mut self, s: usize) { self.size = s; }
//! }
//!
//! impl AbsoluteCircularLinkedList<usize> for MyList {}
//!
//! // 3. Use the provided methods
//! let mut list = MyList {
//! nodes: vec![Node::default(); 5],
//! first: 0, last: 0, size: 0,
//! };
//! list.attach_as_first(1);
//! list.attach_as_last(2);
//! assert_eq!(list.get_size(), 2);
//! assert_eq!(list.get_first(), 1);
//! assert_eq!(list.get_last(), 2);
//! ```

mod link_type;
mod lists;
Expand Down
38 changes: 35 additions & 3 deletions src/link_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,42 @@ use num_traits::{FromPrimitive, Unsigned};
use platform_num::Number;
use std::convert::TryFrom;

/// Extension trait providing the `funty` method for converting small integers to any `LinkType`.
/// Trait for unsigned integer types that can serve as node indices
/// in trees and linked lists.
///
/// `LinkType` combines [`Number`], [`Unsigned`], [`TryFrom<u8>`], and
/// [`FromPrimitive`] and adds a convenience [`funty`](LinkType::funty)
/// method for creating small constants.
///
/// # Blanket implementation
///
/// Every type that satisfies the supertraits automatically implements
/// `LinkType`, so standard unsigned types (`u8`, `u16`, `u32`, `u64`,
/// `usize`) work out of the box:
///
/// ```
/// use platform_trees::LinkType;
///
/// assert_eq!(u32::funty(0), 0u32);
/// assert_eq!(u64::funty(1), 1u64);
/// assert_eq!(usize::funty(42), 42usize);
/// ```
pub trait LinkType: Number + Unsigned + Sized + TryFrom<u8> + FromPrimitive {
/// Convert a small integer (u8) to Self.
/// This is a convenience method for creating zero, one, or small constants.
/// Convert a `u8` value to `Self`.
///
/// This is a convenience method used internally for zero, one,
/// and other small constants needed by tree and list algorithms.
///
/// # Examples
///
/// ```
/// use platform_trees::LinkType;
///
/// let zero = usize::funty(0);
/// let one = u32::funty(1);
/// assert_eq!(zero, 0);
/// assert_eq!(one, 1);
/// ```
fn funty(n: u8) -> Self;
}

Expand Down
27 changes: 27 additions & 0 deletions src/lists/absolute_circular_linked_list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
use crate::{AbsoluteLinkedList, LinkType};

/// Circular doubly-linked list with absolute (direct) head/tail access.
///
/// Provides `attach_before`, `attach_after`, `attach_as_first`,
/// `attach_as_last`, and `detach` operations that maintain circular
/// links and update the head/tail/size automatically.
///
/// All methods have default implementations — an empty `impl` block
/// is sufficient once [`AbsoluteLinkedList`] is implemented.
pub trait AbsoluteCircularLinkedList<T: LinkType>: AbsoluteLinkedList<T> {
/// Inserts `new_element` immediately before `base_element`.
///
/// If `base_element` is the current first element, the first
/// pointer is updated to `new_element`.
fn attach_before(&mut self, base_element: T, new_element: T) {
let base_element_previous = self.get_previous(base_element);
self.set_previous(new_element, base_element_previous);
Expand All @@ -13,6 +25,10 @@ pub trait AbsoluteCircularLinkedList<T: LinkType>: AbsoluteLinkedList<T> {
self.inc_size();
}

/// Inserts `new_element` immediately after `base_element`.
///
/// If `base_element` is the current last element, the last
/// pointer is updated to `new_element`.
fn attach_after(&mut self, base_element: T, new_element: T) {
let base_element_next = self.get_next(base_element);
self.set_previous(new_element, base_element);
Expand All @@ -25,6 +41,10 @@ pub trait AbsoluteCircularLinkedList<T: LinkType>: AbsoluteLinkedList<T> {
self.inc_size();
}

/// Inserts `element` as the first element of the list.
///
/// If the list is empty, `element` becomes both first and last,
/// with its previous and next pointers pointing to itself.
fn attach_as_first(&mut self, element: T) {
let first = self.get_first();
if first == T::funty(0) {
Expand All @@ -38,6 +58,9 @@ pub trait AbsoluteCircularLinkedList<T: LinkType>: AbsoluteLinkedList<T> {
}
}

/// Inserts `element` as the last element of the list.
///
/// If the list is empty, delegates to [`attach_as_first`](Self::attach_as_first).
fn attach_as_last(&mut self, element: T) {
let last = self.get_last();
if last == T::funty(0) {
Expand All @@ -47,6 +70,10 @@ pub trait AbsoluteCircularLinkedList<T: LinkType>: AbsoluteLinkedList<T> {
}
}

/// Removes `element` from the list.
///
/// Updates head/tail pointers as needed and clears the element's
/// previous and next pointers to `T::funty(0)`.
fn detach(&mut self, element: T) {
let element_previous = self.get_previous(element);
let element_next = self.get_next(element);
Expand Down
Loading