liveBook · Manning

Rust

As explained in Code Like a Pro in Rust

Rust is a systems programming language designed to provide memory safety and concurrency safety without garbage collection.

Rust is a compiled, statically typed language for performance- and safety-critical software. It is primarily suited to systems work, but can also target WebAssembly for web applications. Its safety guarantees come with a steeper learning curve and greater compilation-time complexity; choose it when those trade-offs fit the job. section 1.1 section 1.3

The features with the greatest implementation impact are:

  • The borrow checker validates references at compile time. It permits multiple immutable references or one mutable reference, but not both at once; scope determines when resources can be released. section 1.2.1
  • Traits, generics, closures, iterators, macros, and async/await support composition without relying on class inheritance. Cargo handles packages and builds. section 1.2.2 section 1.1
  • Zero-cost abstractions and LLVM optimization make readable code a practical starting point for performance work. Measure and optimize further when the workload demands it. section 11.0

Handle a failing calculation explicitly

For an integer division that may fail, `checked_div` makes the outcome a value: `assert_eq!((100i32).checked_div(0i32), None);`. This is preferable to assuming the divisor is valid; division by zero otherwise panics in the illustrated Rust program. section 4.5.1

Use the compiler’s type and reference checks to narrow what tests must cover—not to replace tests. Test program logic, conversions, stateful operations, and I/O; avoid using `unwrap()` or `unsafe` merely to bypass edge cases. section 6.4

Table 11.1 Rust bindings and tooling for integrating Rust into other languages (view table figure)

Language

Name

Description

URL

GitHub stars1

Python

PyO3

Rust bindings for Python, with tools for making native Python packages with Rust

https://pyo3.rs

10,090

Python

Milksnake

setuptools extension for including binaries in Python packages, including Rust

https://github.com/getsentry/milksnake

783

Ruby

Ruru

Library for building native Ruby extensions with Rust

https://github.com/d-unseductable/ruru

822

Ruby

Rutie

Bindings between Ruby and Rust, which enable integrating Rust with Ruby or Ruby with Rust

https://github.com/danielpclark/rutie

812

Elixir and Erlang

Rustler

Library for creating safe bindings to Rust for Elixir and Erlang

https://github.com/rusterlium/rustler

3,999

JavaScript and TypeScript on Node.js

Neon

Rust bindings for creating native Node.js modules with Rust

https://neon-bindings.com

7,622

Java

jni-rs

Native Rust bindings for Java

https://github.com/jni-rs/jni-rs

1,018

Rust

bindgen

Generates Rust FFI bindings from native Rust

https://github.com/rust-lang/rust-bindgen

3,843

The bindings table identifies options for adding safety-critical or compute-intensive Rust functions to existing Python, Ruby, Elixir, Erlang, and Node.js applications without a complete rewrite. section 11.5 section 11.0

Consider Rust for concurrent systems, embedded software, cryptography, legacy C or C++ replacement, and performance-critical components. If rapid development matters more than its safety and performance properties, another language may be a better fit. section 1.3.1 section 1.3

How Code Like a Pro in Rust covers it

How deep it goes
Explains borrow-checker rules and selected arithmetic and testing consequences, without attempting an exhaustive language reference.
Examples
Uses integer literals, checked division, divide-by-zero behavior, and a bindings table for cross-language integration.
What it assumes
Assumes familiarity with Rust and benefits from systems-language experience; does not spend much time on basic syntax.
What you can do after
Evaluate/understand when Rust’s safety and performance justify its development costs and how to add Rust components to existing applications.
How it connects
Connects Rust to borrowing, RAII, traits, generics, async/await, WebAssembly, and foreign function interfaces.

Also explained in

Compare how 6 books explain Rust →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Code Like a Pro in Rust. The section links point to the parts of the book it draws on.