From the course: Using Rust with Python

Unlock this course with a free trial

Join today to access over 23,200 courses taught by industry experts.

Embedded Rust CLI

Embedded Rust CLI

- [Instructor] Here's a Rust project that I have embedded Python inside. And I'm also going to make it into a command line tool here. And let's go ahead and look at the structure here without any build artifacts. I have the cargo files here, I have a make file, and then I have two files inside of source. So I have a lib.rs and a main.rs. As a side note here, this is a great command tree -I target to find exactly the structure of a Rust project without having to look at the target build. Now if we go ahead and look inside of the lib file first, we can take a look at what's happening. So first up here I have some library code that embeds Python. So this is where there is some Python code that accepts an input. In this case, the input is Marco and it returns back Python if there's Marco. Next, what we do here is we have the Python interface here, we also have the GIL that is being released and then we're able to talk to that function, capture it, and then put input into it and then…

Contents