Need Help Translating C into Rust


Hello, I am working on a little project trying to rewrite the MINIX 3 scheduler in Rust and I need help.

I know that ideally using raw pointers should be avoided, but I am not sure how to do that here.
First, obviously there is no C-like macros, so I replaced all #ifdefs with constants. Another issue is, there is no standard library on MINIX yet, so things like assert! won’t work. I am working on getting the standard library to work on there, but no luck yet.

All structs and typedefs from C were converted using rust-bindgen and placed into a separate mod bindings.

Here is one of the functions of the scheduling algorithm in C:
Here is what I have so far in Rust:

I would appreciate any help!




The code is using a linked list. Linked lists require a shared mutable ownership, which is risky and not allowed by the borrow checker, so you’ll have to use either unsafe raw pointers, or Rc<RefCell<…>> for references to list elements.

Or better, change the algorithm. Get rid of the linked lists completely and use some other container instead, perhaps VecDeque or BinaryHeap.



Thank you so much for your quick response. VecDeque sounds like a great replacement for the linked lists. It seems like I would need the standard library for that to work though, is that correct?



Ah, yes, it’d need std :frowning:

The std implementation is quite big due to it being so flexible, but if you only need to add one element, you might be able to roll your own.