{"id":258,"date":"2022-08-12T02:20:00","date_gmt":"2022-08-12T07:20:00","guid":{"rendered":"http:\/\/sycured.127.0.0.1.sslip.io\/?p=258"},"modified":"2024-01-14T12:10:30","modified_gmt":"2024-01-14T17:10:30","slug":"from-python-to-rust","status":"publish","type":"post","link":"http:\/\/10.42.0.68:8080\/blog\/from-python-to-rust","title":{"rendered":"From Python to Rust"},"content":{"rendered":"\n
Why am I using Rust instead of Python for my new CLI or API?<\/p>\n\n\n\n
Why is it the right move?<\/p>\n\n\n\n\n\n\n\n
I firstly moved complex scripts from Bash to Python due to the simplicity to handle errors and a clear way to manage arguments.<\/p>\n\n\n\n
Main libraries used:<\/p>\n\n\n\n
This easy way has a drawback: Python needs to be installed with all libraries that we’re using.<\/p>\n\n\n\n
Recently, I rewrote a quick shell script in Rust because I wanted real portability and the easiest way to parallelize tasks.<\/p>\n\n\n\n
Main libraries used:<\/p>\n\n\n\n
I use Also, for big projects where requests can’t be handled directly\/easily with them, I switch to reqwest<\/a><\/p>\n\n\n\n This way, I have the perfect portability:<\/p>\n\n\n\n I think that it’s the perfect move.<\/p>\n\n\n\n When you build some tools that can be deployed and used by people using different operating systems, also if they’re not administrators of their workstation, we need to use the right programming language.<\/p>\n\n\n\n In this case, I can’t require the installation of an entire environment (ex: the Python interpreter with the virtual environment for the tool).<\/p>\n\n\n\n In the case of OCI image, it’s about the size\u2026 so how many seconds is needed to start\/run it.<\/p>\n\n\n\n Why will I request the user to use a 200+ MB image when the same tool statically compiled is around 10-20 MB?<\/strong><\/p>\n\n\n\n I haven’t chosen Go<\/a> due to Rust’s safety guarantee:<\/p>\n\n\n\n The safety guarantee is one of the most important aspects of Rust; Rust is memory-safe, null-safe, type-safe, and thread-safe by design. – source<\/a><\/p>\n<\/blockquote>\n\n\n\nattohttpc<\/code> or
ureq<\/code> depending on licenses denied due to the project’s license.<\/p>\n\n\n\n
\n
RUSTFLAGS=\"-C target-feature=+crt-static\"<\/code>)<\/em> to put the binary into a scratch OCI image<\/li>\n<\/ul>\n\n\n\n
Is it the right move?<\/h2>\n\n\n\n
Why not Go?<\/h3>\n\n\n\n
\n