Newbie to Rust: Analyze / Review Code

Hello,

I am newbie to Rust (coming from Python), In order to go beyond toy examples and leetcode like challenges, I decided to build some small tools (only to learn the language) and created a repo GitHub - ninadmhatre/rupy: Python to Rust (small) code example (with some practical use)

Early examples were limited to 1-2 file so I wanted to go beyond that and created this executor project rupy/executor at main · ninadmhatre/rupy · GitHub. Now, this code is working but since i have never written Rust code before, I need some inputs about what could be improved in the code.

my wishlist about this executor project,

  • I want to extend it to run as worker listening to tasks (mpsc ?)
  • Task run with threadpool (worker executes tasks in 1 of the threads)
  • Async tasks (I am just curious if this can be done)

Looking at the current implementation and my wishlist, please suggest how or what can be done here. If you can suggest some reference projects or pointers on how to improve the structure, that will be very helpful.

Thanks for reading through the message.

  • Ninad

Hi,

Welcome to Rust, seems like it's a good project.

I hope I may give you some ideas about your wish list.

1- I think you may try to implement work stealing mechanism like tokio does. You can push tasks through channels(like you said with mpsc). Then your executor takes tasks and decides which thread should it be sent via different strategies(load average, round robin, priority queue etc.).

2- Your executor can claim couple of OS level thread then can use whenever executor needs them to run.

3- It's definitely possible. You can collect async tasks and run them in async scope. Running async tasks in non async can be little problematic in strategic way but take a look at here

I hope these may help.

1 Like

Hello @Tahinli ,

Thanks for taking time to check my code and suggesting references.

How is the code structure? Any improvements possible there?

I'm not a Senior Rust Developer but I think you structured code well. At least it's good for me. Only thing I can say it is Clippy. If you hadn't heard it take a look at it. It will analyze your code and detect general pitfalls and things for you.

I'm sure performance can be improved with lifetime magics and less heap allocations but I'm not the one who can give advice about them a lot.