#linked-list #ffi #list #value #next #documentation #c-linked-list

c_linked_list

Utilities for handling NULL-terminated C linked lists

4 releases (stable)

Uses old Rust 2015

1.1.1 Jun 21, 2018
1.1.0 Feb 9, 2016
1.0.0 Feb 9, 2016
0.1.0 Jan 13, 2016

#10 in #lists

Download history 8717/week @ 2024-12-26 15557/week @ 2025-01-02 22169/week @ 2025-01-09 21545/week @ 2025-01-16 24099/week @ 2025-01-23 24552/week @ 2025-01-30 29186/week @ 2025-02-06 25599/week @ 2025-02-13 27119/week @ 2025-02-20 25563/week @ 2025-02-27 26321/week @ 2025-03-06 25006/week @ 2025-03-13 25464/week @ 2025-03-20 23751/week @ 2025-03-27 24834/week @ 2025-04-03 22015/week @ 2025-04-10

100,378 downloads per month
Used in 212 crates (4 directly)

MIT OR BSD-3-Clause

14KB
275 lines

c_linked_list

This is a Rust library for handling NULL-terminated C linked lists. You can use this library to take a linked list provided by a C library and wrap it as a Rust type.

Documentation


lib.rs:

This crate provides utilities for working with NULL-terminated linked lists provided by C code. Suppose you call a foreign function which returns either NULL or a pointer to a node of the following C type.

struct LinkedListNode {
    int value;
    struct LinkedListNode *next;
};

You can use this library to wrap the C linked list in a rust type, allowing operations such as iteration to be performed on it.

let some_c_linked_list = foreign_function_which_returns_c_linked_list();
let rust_linked_list = unsafe { CLinkedListMut::from_ptr(some_c_linked_list, |n| n.next) };
for (i, node) in rust_linked_list.iter().enumerate() {
    println!("some_c_linked_list[{}] == {}", i, node.value);
}

No runtime deps