Repository: andreiavrammsd/static_vector.rs
Pull request #20: Dev
Author: login: andreiavrammsd
Created: 2025-05-23T04:27:53Z | Merged: 2025-05-23T14:37:27Z



Diff:
diff --git a/.github/doc/doc.py b/.github/doc/doc.py
index 8a19382..a12cd52 100755
--- a/.github/doc/doc.py
+++ b/.github/doc/doc.py
@@ -1,63 +1,93 @@
 #!/usr/bin/env python3
 
+"""
+Multi-version Rust documentation for GitHub Pages.
+
+- Generates documentation for default branch and for the given Git ref.
+- Generates index.html, for each ref, to redirect to crate documentation.
+- Generates main index.html that lists all versions (only semver Git tag) + default branch (skips anything else).
+
+Usage:
+    ./doc.py [ref]
+
+If no ref is provided, it defaults to using "master".
+"""
+
+import re
 import shutil
 import subprocess
 import sys
 from pathlib import Path
 
 
-def clean(docs: Path, ghpages: Path):
+def clean(docs: Path, gh_pages: Path):
+    """Remove and recreate documentation directories."""
     shutil.rmtree(docs, ignore_errors=True)
-    shutil.rmtree(ghpages, ignore_errors=True)
+    shutil.rmtree(gh_pages, ignore_errors=True)
     docs.mkdir(parents=True)
 
 
-def main(current_ref: str):
-    docs = Path("target/docs")
-    build = Path("target/docs_build")
-    redirect_template = Path(".github/doc/index_redirect.html")
-    template = Path(".github/doc/index_template.html")
-    version_template = Path(".github/doc/version_template.html")
-    gh_pages_path = Path("target/gh-pages")
-
-    clean(docs, gh_pages_path)
-
-    # Copy existing versions from gh-pages
-    cmd(f"git worktree add {gh_pages_path} gh-pages -f")
+def copy_existing_versions(gh_pages: Path, docs: Path):
+    """Copy existing versioned documentation from gh-pages to docs."""
+    run_cmd(f"git worktree add {gh_pages} gh-pages -f")
 
-    for item in gh_pages_path.iterdir():
+    for item in gh_pages.iterdir():
         if item.is_dir():
             shutil.copytree(item, docs / item.name)
 
-    # Generate docs for current_ref
-    print(f"Generating docs for {current_ref}...")
-    cmd(f"git checkout {current_ref}")
-    cmd(f"cargo doc --no-deps --target-dir={build}")
 
-    (docs / current_ref).mkdir(parents=True, exist_ok=True)
+def generate_docs(build: Path, docs: Path, git_ref: str, redirect_template: Path):
+    """Generate documentation for the given Git reference."""
+    print(f"Generating docs for {git_ref}...")
+    run_cmd(f"git checkout {git_ref}")
+    run_cmd(f"cargo doc --no-deps --target-dir={build}")
+
+    (docs / git_ref).mkdir(parents=True, exist_ok=True)
     build_doc = build / "doc"
-    shutil.copytree(build_doc, docs / current_ref, dirs_exist_ok=True)
-    shutil.copy2(redirect_template, docs / current_ref / "index.html")
+    shutil.copytree(build_doc, docs / git_ref, dirs_exist_ok=True)
+    shutil.copy2(redirect_template, docs / git_ref / "index.html")
 
-    # Load templates
-    version_tpl = version_template.read_text()
-    template_text = template.read_text()
 
-    # Prepare refs list: master + tags sorted descending semver
-    tags = cmd("git tag").splitlines()
+def get_version_refs() -> list[str]:
+    """Get a list of version refs: sorted tags."""
+    tags = run_cmd("git tag").splitlines()
     tags.sort(reverse=True, key=lambda s: list(map(int, s.lstrip("v").split("."))))
-    refs = ["master"] + tags
+    return tags
+
+
+def generate_main_index(
+    docs: Path, version_template: Path, index_template: Path, refs: list[str]
+):
+    """Generate the main index.html for the docs site."""
+    version_tpl = version_template.read_text()
+    index_tpl = index_template.read_text()
 
-    # Generate main index.html
     version_list = ""
     for ver in refs:
         version_list += version_tpl.format(version=ver)
 
-    index_html = template_text.format(versions=version_list)
+    index_html = index_tpl.format(versions=version_list)
+    index_html = re.sub(r" +", " ", index_html.replace("\n", ""))
     (docs / "index.html").write_text(index_html)
 
 
-def cmd(cmd: str):
+def main(ref: str, default_ref: str):
+    docs = Path("target/docs")
+    build = Path("target/docs_build")
+    redirect_template = Path(".github/doc/index_redirect.html")
+    index_template = Path(".github/doc/index_template.html")
+    version_template = Path(".github/doc/version_template.html")
+    gh_pages = Path("target/gh-pages")
+
+    clean(docs, gh_pages)
+    copy_existing_versions(gh_pages, docs)
+    generate_docs(build, docs, ref, redirect_template)
+
+    refs = [default_ref] + get_version_refs()
+    generate_main_index(docs, version_template, index_template, refs)
+
+
+def run_cmd(cmd: str):
     result = subprocess.run(
         cmd.split(),
         stdout=subprocess.PIPE,
@@ -70,7 +100,8 @@ def cmd(cmd: str):
 
 if __name__ == "__main__":
     try:
-        main(sys.argv[1] if len(sys.argv) > 1 else "master")
+        default_branch = "master"
+        main(sys.argv[1] if len(sys.argv) > 1 else default_branch, default_branch)
     except subprocess.CalledProcessError as e:
         print(e.stderr)
         sys.exit(1)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9bec3ff..b099c22 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -45,10 +45,10 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v4
-      - uses: dtolnay/rust-toolchain@stable
+      - uses: dtolnay/rust-toolchain@nightly
         with:
           components: rustfmt
-      - run: cargo fmt --all -- --check
+      - run: cargo +nightly fmt --all -- --check
 
   clippy:
     runs-on: ubuntu-latest
diff --git a/Makefile b/Makefile
index 9b6d554..c0398a8 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ test:
 	cargo test
 
 fmt:
-	cargo fmt --all -- --check || (cargo fmt --all && exit 1)
+	cargo +nightly fmt --all -- --check || (cargo +nightly fmt --all && exit 1)
 
 lint:
 	cargo clippy --all-targets --all-features
diff --git a/README.md b/README.md
index 0d08412..f04aad5 100644
--- a/README.md
+++ b/README.md
@@ -73,4 +73,6 @@ See more examples in the documentation of [`Vec`].
 
 ## Development on Linux
 
-See [Makefile](https://github.com/andreiavrammsd/static_vector.rs/blob/master/Makefile).
+* Install [Rust](https://www.rust-lang.org/tools/install) (stable is used for main code, nightly is used only for code formatting and fuzz tests).
+* If using VS Code, see [setup](https://github.com/andreiavrammsd/static_vector.rs/tree/master/.vscode).
+* See [Makefile](https://github.com/andreiavrammsd/static_vector.rs/blob/master/Makefile).
diff --git a/rustfmt.toml b/rustfmt.toml
index 12c6f31..7ebac41 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,3 +1,8 @@
+style_edition = "2024"
+group_imports = "StdExternalCrate"
+imports_granularity = "Module"
+format_code_in_doc_comments = true
+use_field_init_shorthand = true
 max_width = 100
 hard_tabs = false
 use_small_heuristics = "Max"
diff --git a/src/lib.rs b/src/lib.rs
index d560f0e..e5cc0b8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,7 +2,8 @@
 #![deny(missing_docs)]
 #![doc = include_str!("../README.md")]
 
-use core::{error, fmt, mem::MaybeUninit, slice};
+use core::mem::MaybeUninit;
+use core::{error, fmt, slice};
 
 /// Error for when the vector is full or the requested operation would need more space than the capacity.
 ///
@@ -72,7 +73,7 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
     ///
     /// let vec = Vec::<i32, 10>::new();
     /// const SOME_LIMIT: usize = 5;
-    ///     
+    ///
     /// if vec.len() < vec.capacity() - SOME_LIMIT {
     ///     // do something
     /// }
@@ -236,7 +237,7 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
     ///
     /// #[derive(Debug)]
     /// enum AppError {
-    ///     MyFnError
+    ///     MyFnError,
     /// }
     ///
     /// fn my_fn(vec: &mut Vec<i32, 200>) -> Result<(), AppError> {
@@ -290,7 +291,7 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
     /// use static_vector::Vec;
     ///
     /// let mut vec = Vec::<i32, 20>::new();
-    ///     
+    ///
     /// match vec.first() {
     ///     Some(num) => {
     ///         let _ = num;
@@ -315,10 +316,10 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
     /// use static_vector::Vec;
     ///
     /// let mut vec = Vec::<i32, 20>::new();
-    ///     
+    ///
     /// if let Some(num) = vec.first_mut() {
-    ///    *num = 1;
-    ///    let _ = num;
+    ///     *num = 1;
+    ///     let _ = num;
     /// }
     /// ```
     #[must_use]
@@ -336,7 +337,7 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
     /// use static_vector::Vec;
     ///
     /// let mut vec = Vec::<i32, 30>::new();
-    ///     
+    ///
     /// if let Some(num) = vec.last() {
     ///     let _ = num;
     ///     // do something with the last element
@@ -359,8 +360,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
     /// let mut vec = Vec::<i32, 20>::new();
     ///
     /// if let Some(num) = vec.last_mut() {
-    ///    *num = 1;
-    ///    let _ = num;
+    ///     *num = 1;
+    ///     let _ = num;
     /// }
     /// ```
     #[must_use]
@@ -378,7 +379,7 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
     /// use static_vector::Vec;
     ///
     /// let mut vec = Vec::<i32, 20>::new();
-    ///     
+    ///
     /// match vec.get(22) {
     ///     Some(num) => {
     ///         let _ = num;
@@ -410,7 +411,7 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
     /// use static_vector::Vec;
     ///
     /// let mut vec = Vec::<i32, 20>::new();
-    ///     
+    ///
     /// if vec.push(1).is_ok() {
     ///     *vec.get_mut(0).unwrap() = 5;
     /// }
@@ -524,7 +525,7 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
     /// let mut vec = Vec::<i32, 20>::new();
     ///
     /// for num in vec.iter_mut() {
-    ///    *num *= 2;
+    ///     *num *= 2;
     /// }
     /// ```
     #[inline]
@@ -570,7 +571,7 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
     /// use static_vector::Vec;
     ///
     /// let mut vec = Vec::<i32, 10>::new();
-    ///     
+    ///
     /// if vec.set_len(5).is_ok() {
     ///     vec.as_mut_slice().fill(1);
     /// } else {


Reviews:
state: APPROVED
author_association: NONE
submitted_at: 2025-05-23T04:28:55Z
state: APPROVED
author_association: NONE
submitted_at: 2025-05-23T12:47:51Z
state: APPROVED
author_association: NONE
submitted_at: 2025-05-23T12:48:52Z

Review comments:
diff_hunk: @@ -1,3 +1,8 @@
+style_edition = "2024"
path: rustfmt.toml
body: Are you sure about using `style_edition = "2024"` in rustfmt.toml? This appears to be a future edition that may not be stable yet. Consider using "2021" which is the current stable edition.
created_at: 2025-05-23T04:28:55Z
author_association: NONE
diff_hunk: @@ -1,63 +1,93 @@
 #!/usr/bin/env python3
 
+"""
+Multi-version Rust documentation for GitHub Pages.
+
+- Generates documentation for default branch and for the given Git ref.
+- Generates index.html, for each ref, to redirect to crate documentation.
+- Generates main index.html that lists all versions (only semver Git tag) + default branch (skips anything else).
+
+Usage:
+    ./doc.py [ref]
+
+If no ref is provided, it defaults to using "master".
path: .github/doc/doc.py
body: Have you considered using a constant for the default branch name in .github/doc/doc.py? It appears in multiple places (line 13 in the docstring and line 103 as `default_branch = "master"`). Using a module-level constant would make future branch name changes easier.
created_at: 2025-05-23T12:48:52Z
author_association: NONE

PR comments:
user: login: ghost
created_at: 2025-05-23T04:27:57Z
body: <h3>Pull Request Revisions</h3>
<table><tr><th>Revision</th><th>Description</th></tr><tr><td><a href="https://review.ai/pr/andreiavrammsd/static_vector.rs/20?rev=3">r3</a></td><td><details open><summary>Added explicit nightly Rust toolchain</summary>Modified fmt job to explicitly use nightly Rust toolchain when running <code>cargo fmt</code></details></td></tr><tr><td><a href="https://review.ai/pr/andreiavrammsd/static_vector.rs/20?rev=2">r2</a></td><td><details><summary>Simplified Rust formatting workflow configuration</summary>Modified CI workflow to remove explicit nightly toolchain specification for cargo fmt command</details></td></tr><tr><td><a href="https://review.ai/pr/andreiavrammsd/static_vector.rs/20?rev=1">r1</a></td><td><details><summary>Refactored documentation generation script</summary>Improved documentation generation script with modularized functions, better error handling, and added documentation generation logic</details></td></tr></table><hr/>✅ AI review completed for <a href="https://review.ai/pr/andreiavrammsd/static_vector.rs/20?rev=3">r3</a><details><summary>Help</summary>
React with emojis to give feedback on AI-generated reviews:
<ul>
<li>👍 means the feedback was helpful and actionable</li>
<li>👎 means the feedback was incorrect or unhelpful</li>
</ul>
💬 Replying to feedback with a comment helps us improve the system. Your input also contributes to shaping future interactions with the AI reviewer.
<br/><br/>
We'd love to hear from you—reach out anytime at <a href="mailto:team@review.ai">team@review.ai</a>.
</details>
author_association: NONE
user: login: codecov[bot]
created_at: 2025-05-23T04:28:55Z
body: ## [Codecov](https://app.codecov.io/gh/andreiavrammsd/static_vector.rs/pull/20?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrei+Avram) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 100.00%. Comparing base [(`5a7bc58`)](https://app.codecov.io/gh/andreiavrammsd/static_vector.rs/commit/5a7bc5815731a676027bf22340359f5bbd1a26ff?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrei+Avram) to head [(`4025504`)](https://app.codecov.io/gh/andreiavrammsd/static_vector.rs/commit/402550447a835303c19452ca5708d01fe1e34bbd?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrei+Avram).
> Report is 1 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##            master       #20   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          448       448           
=========================================
  Hits           448       448           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/andreiavrammsd/static_vector.rs/pull/20?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrei+Avram).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrei+Avram).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
author_association: NONE