Book Image

Hands-On Functional Programming in Rust

By : Andrew Johnson
Book Image

Hands-On Functional Programming in Rust

By: Andrew Johnson

Overview of this book

Functional programming allows developers to divide programs into smaller, reusable components that ease the creation, testing, and maintenance of software as a whole. Combined with the power of Rust, you can develop robust and scalable applications that fulfill modern day software requirements. This book will help you discover all the Rust features that can be used to build software in a functional way. We begin with a brief comparison of the functional and object-oriented approach to different problems and patterns. We then quickly look at the patterns of control flow, data the abstractions of these unique to functional programming. The next part covers how to create functional apps in Rust; mutability and ownership, which are exclusive to Rust, are also discussed. Pure functions are examined next and you'll master closures, their various types, and currying. We also look at implementing concurrency through functional design principles and metaprogramming using macros. Finally, we look at best practices for debugging and optimization. By the end of the book, you will be familiar with the functional approach of programming and will be able to use these techniques on a daily basis.
Table of Contents (12 chapters)

Code Organization and Application Architecture

  1. What are four ways of grouping code into modules?

Our workshop model has four ways of grouping code together: by type, by purpose, by layer, and by convenience.

  1. What does FFI stand for?

FFI stands for Foreign Function Interface.

  1. Why are unsafe blocks necessary?

The unsafe syntax in Rust indicates that you want to use superpowers and that you accept the responsibility.

  1. Is it ever safe to use unsafe blocks?

Nothing is safe. There is an ongoing effort by core Rust developers to rewrite standard library code to use fewer unsafe features. Still, depending on how far down you look, there is no absolute safety in any context. For example, the core compiler is just assumed to always be logically consistent with regards to safety checks (hopefully it is).

  1. What is the difference between a libc::c_int and an i32?

c_int is a direct...