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
46 changes: 46 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build & test

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

env:
CARGO_TERM_COLOR: always

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
strategy:
matrix:
rust:
- stable
- nightly
os:
- ubuntu-latest
- macos-latest
- windows-latest
exclude:
- rust: stable
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Setup ${{ matrix.rust }} Rust toolchain with caching
uses: brndnmtthws/rust-action@v1
with:
toolchain: ${{ matrix.rust }}
cargo-packages: |
cargo-nextest
cargo-tarpaulin
- run: cargo build
- run: cargo nextest run
env:
RUST_BACKTRACE: 1
- run: cargo fmt --all -- --check
if: ${{ matrix.rust == 'nightly' && matrix.os == 'ubuntu-latest' }}
- run: cargo clippy -- -D warnings
34 changes: 34 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish to crates.io

on:
push:
tags:
- v*
env:
CARGO_TERM_COLOR: always

permissions:
contents: write
discussions: write

jobs:
build-test-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: brndnmtthws/rust-action@v1
with:
toolchain: stable
- run: cargo build
- run: cargo test
- run: cargo login ${{ secrets.CRATES_IO_TOKEN }}
- run: cargo publish
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: false
prerelease: false
discussion_category_name: General
generate_release_notes: true
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
//!
//! `rust_ds` is a collection of data structures utilities to use in Rust.

use linked_lists::Double;
use linked_lists::Singly;
pub mod linked_lists;
21 changes: 15 additions & 6 deletions src/linked_lists/double/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ use std::fmt::Debug;
use std::rc::Rc;

/// `Double` is a double linked list referencing the head, the tail node node and the length of the list.
pub struct Double<T: Clone> {
#[derive(Debug)]
pub struct Double<T> {
head: Option<Rc<RefCell<Node<T>>>>,
tail: Option<Rc<RefCell<Node<T>>>>,
len: usize,
}

impl<T> Default for Double<T>
where
T: Debug + PartialEq + Clone,
{
fn default() -> Self {
Self::new()
}
}

impl<T> Double<T>
where
T: Debug + PartialEq + Clone,
Expand Down Expand Up @@ -88,7 +98,6 @@ where
current
.as_ptr()
.as_mut()
.take()
.unwrap()
.get_next_mut()
.replace(next_next.clone());
Expand Down Expand Up @@ -210,8 +219,8 @@ where
Some(tail) => {
let tail = tail.clone();
let previous = tail
.borrow()
.get_previous()
.borrow_mut()
.get_previous_mut()
.clone()
.unwrap()
.upgrade()
Expand All @@ -224,7 +233,7 @@ where
}
}

fn print(&self) {
pub fn print(&self) {
if self.is_empty() {
println!("{}", Error::EmptyList);
}
Expand Down Expand Up @@ -252,7 +261,7 @@ where
let mut current_index = 0;

while current_index <= index {
let current_ref = current.as_ref().clone().unwrap();
let current_ref = current.as_ref().unwrap();
if current_index == index {
return Ok(Some(current_ref.borrow().get_value().clone()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/linked_lists/node/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ mod tests {
.as_ptr()
.as_mut()
.unwrap()
.get_previous()
.get_previous_mut()
.as_ref()
.unwrap()
.upgrade()
Expand Down
14 changes: 12 additions & 2 deletions src/linked_lists/singly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ pub struct Singly<T> {
len: usize,
}

impl<T> Default for Singly<T>
where
T: Debug + PartialEq + Clone,
{
fn default() -> Self {
Self::new()
}
}

impl<T> Singly<T>
where
T: Debug + PartialEq + Clone,
Expand Down Expand Up @@ -146,11 +155,11 @@ where
Ok(None)
}

fn print(&self) {
pub fn print(&self) {
let mut current = &self.head;
while let Some(node) = current {
print!("{:?} -> ", node.get_value());
current = &node.get_next();
current = node.get_next();
}
println!("None");
}
Expand Down Expand Up @@ -206,6 +215,7 @@ mod test {
assert_eq!(list.pop().unwrap().unwrap(), 2);
assert_eq!(list.pop().unwrap().unwrap(), 1);
assert_eq!(list2.get(2).unwrap(), Some(&"rust"));
list2.print();
}

#[test]
Expand Down
Loading