1 of 22

2 of 22

Tales from FFI

Building in Rust for Python

🦀 ❤️ 🐍

Ishan Bhanuka

@twitu

Rust India July Meetup

3 of 22

Intro Briefly

🤯🤪

4 of 22

Cover we will

  • What?
  • How?
  • Enough talk, Now code
  • When to use?

5 of 22

What?

6 of 22

What?

7 of 22

What?

8 of 22

9 of 22

How?

  • Control flow?
  • Data transfer?
  • Data representation?
  • Memory management?

10 of 22

How? Control Flow?

11 of 22

How? Control Flow?

12 of 22

How? Data transfer?

13 of 22

How? Data transfer?

14 of 22

How? Data transfer?

15 of 22

How? Data representation?

16 of 22

How? Memory management?

17 of 22

18 of 22

Working Example

Rust logger for Python

🦀 ❤️ 🐍

19 of 22

When to FFI?

  • Technically possible?
  • Fits the context?

Biggest benefit??

  • Performance 🤤
  • Correctness 🏎️
  • Maintainer velocity 🧑‍💻

20 of 22

21 of 22

Advanced Patterns

  • Generics - Void pointer + Tag
  • Accessing Python objects in Rust
  • Async stuff
  • Interfacing Rust and Cython

22 of 22

References