Skip to content

Publish doc #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 20, 2025
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
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,21 @@ jobs:

doc:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo doc
- run: cargo doc --no-deps
- run: |
echo '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=static_vector/index.html" /></head></html>' > target/doc/index.html
if: github.ref == 'refs/heads/master'
- uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
publish_branch: gh-pages
if: github.ref == 'refs/heads/master'

clippy:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ bench:
xdg-open target/criterion/push\ and\ clear/report/index.html

doc:
cargo doc --open
cargo doc --no-deps --open

build-doc:
cargo doc
cargo doc --no-deps

dev:
echo Installing pre-commit hook...
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![license](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![build](https://github.com/andreiavrammsd/static_vector.rs/workflows/CI/badge.svg)](https://github.com/andreiavrammsd/static_vector.rs/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/andreiavrammsd/static_vector.rs/graph/badge.svg?token=pCcpya0mZC)](https://codecov.io/gh/andreiavrammsd/static_vector.rs)
[![documentation](https://img.shields.io/badge/Documentation-static_vector-4EC820.svg)](https://andreiavrammsd.github.io/static_vector.rs/)

A no-std, stack-allocated vector with fixed capacity and dynamic length.

Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ impl<T: Clone, const CAPACITY: usize> Vec<T, CAPACITY> {

/// Returns the maximum number of elements the vector can contain.
#[inline(always)]
#[doc(alias("max", "size", "limit", "length"))]
pub fn capacity(&self) -> usize {
CAPACITY
}

/// Returns the maximum number of elements the vector currenly contains.
#[inline(always)]
#[doc(alias("length", "size"))]
pub fn len(&self) -> usize {
self.length
}
Expand All @@ -79,6 +81,7 @@ impl<T: Clone, const CAPACITY: usize> Vec<T, CAPACITY> {
///
/// Returns [`CapacityExceededError`] if the vector is already at full capacity.
#[inline]
#[doc(alias("add", "append", "insert"))]
pub fn push(&mut self, value: &T) -> Result<(), CapacityExceededError> {
if self.length == CAPACITY {
return Err(CapacityExceededError);
Expand All @@ -92,6 +95,7 @@ impl<T: Clone, const CAPACITY: usize> Vec<T, CAPACITY> {

/// Removes all elements. Size will be zero.
#[inline]
#[doc(alias("reset", "remove", "truncate", "empty"))]
pub fn clear(&mut self) {
self.drop(0, self.length);
self.length = 0
Expand All @@ -107,6 +111,7 @@ impl<T: Clone, const CAPACITY: usize> Vec<T, CAPACITY> {
/// # Errors
///
/// Returns [`LengthTooLargeError`] if `new_length` exceeds the vector's fixed capacity.
#[doc(alias("resize", "length"))]
pub fn set_len(&mut self, new_length: usize) -> Result<(), LengthTooLargeError>
where
T: Default,
Expand All @@ -130,27 +135,31 @@ impl<T: Clone, const CAPACITY: usize> Vec<T, CAPACITY> {
/// Returns a reference to the first element in the vector, or [`None`] if the vector is empty.
#[must_use]
#[inline]
#[doc(alias("front", "head", "start"))]
pub fn first(&self) -> Option<&T> {
if self.length == 0 { None } else { Some(unsafe { &*self.data[0].as_ptr() }) }
}

/// Returns a reference to the last element in the vector, or [`None`] if the vector is empty.
#[must_use]
#[inline]
#[doc(alias("back", "tail", "end"))]
pub fn last(&self) -> Option<&T> {
if self.length == 0 { None } else { Some(unsafe { &*self.data[self.length - 1].as_ptr() }) }
}

/// Returns a reference to the element at the specified `index`, or [`None`] if out of bounds.
#[must_use]
#[inline]
#[doc(alias("at", "index"))]
pub fn get(&self, index: usize) -> Option<&T> {
if index >= self.length { None } else { Some(unsafe { &*self.data[index].as_ptr() }) }
}

/// Returns a mutable reference to the element at the specified `index`, or [`None`] if out of bounds.
#[must_use]
#[inline]
#[doc(alias("at", "index"))]
pub fn get_mut(&mut self, index: usize) -> Option<&mut T> {
if index >= self.length {
None
Expand All @@ -162,6 +171,7 @@ impl<T: Clone, const CAPACITY: usize> Vec<T, CAPACITY> {
/// Returns (and removes) the last element from the vector, or [`None`] if the vector is empty.
#[must_use]
#[inline]
#[doc(alias("remove", "get"))]
pub fn pop(&mut self) -> Option<T> {
if self.length == 0 {
None
Expand All @@ -175,6 +185,7 @@ impl<T: Clone, const CAPACITY: usize> Vec<T, CAPACITY> {
/// or [`None`] if the vector is empty or the predicate returns false.
#[must_use]
#[inline]
#[doc(alias("remove", "get"))]
pub fn pop_if(&mut self, predicate: impl FnOnce(&T) -> bool) -> Option<T> {
let last = self.last()?;
if predicate(last) { self.pop() } else { None }
Expand Down