Help in developing Stack in Rust from Equivalent C code

Need help/advise in converting am equivalent C code for a simple Stack (using linked list) into Rust.

Files are uploaded into Files

  1. Stack_C_Methods.txt has C Code
  2. main.rs is the code i started to re-write the stack implementation using Rust.
  3. CompilingErrors.txt shows the Compilation error encountered from my Rust code

i need some help

a. to fix the compilation errors mentioned in CompilingErrors.txt
Or
b. Another code/approach for the stack implementation without using "Option" as i did in my code.

Appreciate your all help in this.

Linked lists are a notoriously bad fit for Rust, and implementing linked lists a particularly bad fit for learning Rust. If this is just for learning purposes, my advice is to pick a project that's doesn't inherently involve pointer-based data structures (much less implementing a pointer-based data structure).

If it's for practical purposes, just use push/pop on a Vec instead. (There is a LinkedList in std too, but as even the documentation says, you almost never want to use it.)

If you choose to pursue the "implement a linked list" path anyway, here's an entire book about it.


Anyway, here's a cleaned up version of your Rust code.

8 Likes

Thanks for the great help here and for the cleaned-up code, helped me a lot

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.