Calling Rust code from Python

preview_player
Показать описание
Today we are learning how to call Rust code from Python!

#rust #programming #tutorial
Рекомендации по теме
Комментарии
Автор

I followed a web guide to use Rust code from within a Python Dash web app. It blows my mind how many different ways there are to do things in programming. Makes it very difficult to learn.

pdblouin
Автор

I am slowly moving over to Rust from C++ since I have come to despise the package management in it. Cargo provides easy-to-use package management, which I love dearly. Now I can focus more on the actual logic than worrying about how to link up my whole code. However, sometimes I wish to access Rust's robustness and 'easy-to-use'-ness through C/C++. So, please, it'll be beneficial if you make a video on how to call Rust from C/C++ and vice versa.

PS: I really love your videos. If possible, I would love to get in touch with you to discuss Rust's future prospects and how to improve myself in this language.

utsavbasu
Автор

Important detail: `maturin develop` creates a slow, unoptimized build. Use `maturin develop --release` for fast execution.

jabuci
Автор

Love the channel, Bogdan! I kind of just stopped learning Rust until I came across your channel and you’ve reinvigorated my interest. I appreciate your work, my dude!!

TRLYx
Автор

Wow, timing is perfect, just finishing my diploma where I use PyTorch in Rust

MrMediator
Автор

This is such an amazingly concise quick start. Did not realise Maturin existed to bridge the tooling between languages so well. Thank you! 🙏🏻

JoshPeak
Автор

The fact that Rust can build a C compatible shared library, which is what Rust calls a cdylib, is really important. This feature combined with FFI exports enables support not just for C and C++, but for a whole series of other programming languages too.
And although I am still quite new to the Rust itself, this realization has already triggered me to explore several things.
In this way I know that for Java there is really good JNI crate, and which is also really straightforward to use due to the abstractions in this crate. And if you have ever used JNI in C with the regular header files, and know how much of a serious pain that is to use, then it's actually really great what the authors of the crate have done.
But since I am mostly a C# dotnet developer while not being scared to make make hands dirty on low level stuff, I also know how to use libraries with PInvoke, while taking care to use the Cdecl calling convention, mapping correct data type sizes and things like that.

jongeduard
Автор

That looks seamless and reasonable. Great demo

jesusmtz
Автор

Really great content. As I recall, other similar cross language integrations often lose a good bit of performance when jumping between the hidden glue code that allows them to be used together (such as Java with C++). Best practice is to make course-grained functions in the lower-level language (such as rust in this case). This way you do not waste too much time going back and forth across languages before calling the more important function which will do the bulk of the work.

mkvalor
Автор

Your content has helped me learn rust tremendously well

Ryan-xqkl
Автор

Wow, I'm constantly diappointed you don't have a merch store or such, because I'm always binge-watching your wonderful content. I would love to see Rust integrated with Lua, as Lua is a wonderful language designed to be embedded into lower-level software environment like C/C++.

mutley
Автор

More guides on how to integrate Rust into other languages like Dart/Flutter would be great!

jakobdunnebeil
Автор

This is quite possibly the coolest thing I’ve ever seen

paulzupan
Автор

This but a real life example where we can drop in rust for some kind of expensive function in prod and get some massive juicy speed up

JOHNSMITH-verq
Автор

Really good content. Short and concise!

dazealex
Автор

Great content, some how we need another version too: "Calling Python from Rust"

ThanhHoQuangCSE
Автор

I love the channel and its definitely helping me fall in love with the language! Could you do a similar video to call rust from Node?

ndil-adjimsoungadoy
Автор

I've already done so from Java and Kotlin. It was even faster than calling normal c or c++ via JNI.

gendrik
Автор

This was awesome thankyou :) I'd love more videos integrating with python please! PyO3's type mechanisms for guarding the GIL are unbelievably difficult to understand for more complex tasks... it uses `std::marker::PhantomData` which melted my brain a bit... I gave up trying to understand it.

EngineerNick
Автор

an example of using Python from Rust would also be interesting.

danielsan