| Crates.io | rusty_list |
| lib.rs | rusty_list |
| version | 0.1.2 |
| created_at | 2025-04-06 04:37:53.201733+00 |
| updated_at | 2025-06-29 15:56:24.112866+00 |
| description | A no_std compatible, intrusive doubly linked list implementation. |
| homepage | https://github.com/iiTONELOC/rusty_list |
| repository | https://github.com/iiTONELOC/rusty_list |
| max_upload_size | |
| id | 1622632 |
| size | 126,547 |
RustyList is a safe, intrusive doubly-linked list crate for Rust. It provides a way to embed list nodes directly within your data structures (similar to Linux kernel's list_head), allowing efficient in-place list management with no heap allocation. RustyList is #![no_std] compatible and ensures that all unsafe operations are confined internally, presenting a clean 100% safe public API.

#![no_std] environments, ideal for embedded systems, kernels, and other low-level applications where heap allocation or the standard library may not be available. RustyList allocates no memory on its own.RustyListNode within it. This means no separate node allocations – your struct itself carries the pointers for list links.unsafe code to use RustyList. All pointer arithmetic and aliasing trickery are handled internally.push, pop, insert, remove, and find_equal.RustyListNode<T>.HasRustyNode for that struct.RustyList<T> and set the offset using .new() or .new_with_order().insert, push, pop, remove, find_equal as needed.Example:
#[repr(C)]
struct MyStruct {
value: u32,
node: RustyListNode<MyStruct>,
}
impl HasRustyNode for MyStruct {
fn rusty_offset() -> usize {
rusty_offset(|s: &Self| &s.node)
}
}
🔒
#[repr(C)]is required to ensure predictable field layout for offset math.
Used for sorted insert() and find_equal():
fn my_cmp(a: *const MyStruct, b: *const MyStruct) -> i32 {
unsafe {
(*a).value.cmp(&(*b).value) as i32
}
}
let mut list = RustyList::<MyItem>::new_with_order(|a, b| a.value.cmp(&b.value));
let mut item = MyItem { value: 42, node: RustyListNode::new() };
list.insert(&mut item);
let mut list = RustyList::<MyStruct>::new_with_order(my_cmp);
for item in my_items.iter_mut() {
list.insert(item) ;
}
list.push(&mut my_item);
let item = list.pop();
if let Some(ptr) = list.find_equal(&target) {
list.remove(ptr);
}
list.remove(ptr);
All core operations are covered with unit tests:
insert (sorted + head/tail/middle)remove (head, tail, middle)push and pop (non-sorted FIFO)find_equal via order functionTo run tests:
cargo test
Note:
stdis enabled during tests to allow use ofVec,assert_eq!, etc.
RustyListNode per list per item.| Name | Contact |
|---|---|
| Anthony Tropeano | GitHub |
This project is distributed under the MIT License. See LICENSE for details.