Rust Coding Conventions and Learning Resources

Rust Coding Conventions and Learning Resources

  • April 22, 2024
  • 10 min read
  • Rust programming
Table of Contents

What coding style should I adopt for my Rust code to ensure consistency with my favorite Rust libraries? Where can I learn to develop a specific application using Rust and which libraries should I utilize? How can I make the most of Rust development tools?

Is there a specific place I can visit to find resources that will aid me in answering these questions?

This post serves as our index to resources that help developers like you master Rust and write excellent Rust code. If you haven’t started learning Rust yet, begin by:

We’ll update the content as needed to include new relevant resources.

Idiomatic Coding Guidelines

Coding guidelines are essential because they improve code consistency, readability, and understanding. It’s easier to navigate an unfamiliar codebase when it resembles a familiar one.

Below are resources to help you make your Rust code idiomatic and adhere to Rust’s best practices.

API Design Guidelines

APIs (Application Programming Interfaces) are intended to be called by other programmers. Therefore, it’s crucial to design them for ease of use and maintenance. Below are relevant resources.

Code Styling Guidelines

Code styling involves a set of formatting rules that define how code should appear. These rules cover indentation, function definition, line width, line breaks, and more. Consistent styling enhances code readability. The Rustfmt tool automatically formats Rust code according to a predefined idiomatic style. Below are resources detailing idiomatic Rust’s code style.

Code Design Patterns

Design patterns dictate how to structure Rust code and leverage Rust’s characteristics to write productive, efficient, and easily understandable code. Explore the following resources to learn Rust design patterns:

  • Rust Design Patterns (Unofficial): An mdBook offering good Rust code design practices as patterns. It demonstrates how to utilize various Rust features to ensure code is easily understandable and maintainable. The book covers Rust programming idioms, design patterns (recommended practices), and antipatterns (things to avoid).
  • Effective Rust (Unofficial): An mdBook presenting many ways to enhance your Rust code. It provides insights on when to use macros and how to reason about lifetimes with generics. Additionally, it draws parallels with C++, which can be particularly beneficial for C++ developers.
  • Rust Performance Pitfalls (Unofficial): A blog article highlighting both the best practices and common pitfalls for writing performant Rust code.
  • The Rust Performance Book (Unofficial): An mdBook that provides “techniques that can improve the performance-related characteristics of Rust programs, such as runtime speed, memory usage, and binary size”.

Comments Guidelines

Comments enhance the clarity of code. Below are resources providing guidelines for commenting code in Rust:

Documentation Guidelines

There are established methods for writing effective documentation for Rust programs. Below are recommendations for documenting Rust code idiomatically:

Error Handling

Error handling is crucial in software development. Poor error handling can make code harder to read and introduce bugs. Here are resources that offer good practices for error handling in Rust code:

Naming Convention Recommendation

Consistency in naming program elements enhances code readability. The following guides provide Rust’s idiomatic approach to naming identifiers (variables, constants, function names, etc), types, and more.

Testing Guidelines

Do you test your code? Testing is essential in software development to quickly detect bugs introduced by changes and to facilitate code maintenance by other developers. Below are resources demonstrating how to organize tests for Rust programs and how to integrate testing into your workflow:

Development and Tool Resources

Learning Rust to build various apps, knowing the right library crates for each problem, and mastering Rust’s development tools are all essential skills. These Rust learning resources can help you excel in all these aspects.

Resources by Application Type

Explore resources tailored to specific types of software applications.

Asynchronous Applications

Async programming facilitates the development of high-performance I/O-bound software.

Rust has no built-in async runtime but relies on community-built runtimes like Tokio, Async-std and Smol.

Command Line Applications

Guides for developing CLI applications like terminal utilities.

Embedded Software

Resources for using Rust in embedded systems development:

Graphical User Interface (GUI)

Explore GUI frameworks.

Graphics and Games

Resources for graphics and game development.

Machine Learning and Data

Rust community supports data analysis and machine learning.

Web Applications

In this connected world where remote services are increasingly prevalent, web applications continue to be in demand. Below are resources to learn how to develop web applications with Rust, along with popular frameworks to use.

Tools and Libraries Learning

Explore resources that provide insights into various crates for different applications of Rust and help you better understand and utilize Rust development tools.

Build Systems, Package Management, and Other Tools

  • Cargo Book: Official book for using Cargo, the Rust build and package management tool.
  • Clippy Documentation: A guide covering the usage and development aspects of Clippy, the Rust linter.
  • Clippy Lints Documentation: Detailed explanation of all the lint rules implemented in Clippy, categorized by Clippy version.

Development Environment

Rust Compiler

Extra

  • The Rust Reference Book: The “primary reference for the Rust programming language”. You can find descriptions of Rust’s language features, how it functions, and the motivations behind its design.
  • The Little Book of Rust Books: A curated list of official, unofficial and application-specific Rust books.
  • Awesome Rust Books: A compilation of free and paid books for learning Rust programming and applying Rust for various purposes.
  • List of Websites that Track the State of Rust in Related Areas: Links to websites tracking Rust’s progress in different domains.
  • Awesome Rust: A comprehensive categorized list of Rust crates, along with learning resources such as books, podcasts, and blog articles.
  • Rust-learning: A collection of links to various resources for learning Rust, including blogs, books, videos, podcasts, and more.
  • Idiomatic-rust: Numerous resources for writing “ergonomic Rust code”.
  • Rust CookBook: Tips on how to implement common programming tasks in Rust, covering various domains.

Do you use relevant Rust programming resources that haven’t been mentioned in this post?
Feel free to share them in the comments section or let us know.

Related Posts

Setting Up and Using Rust Offline for Seamless Development: A Step-by-Step Tutorial

Setting Up and Using Rust Offline for Seamless Development: A Step-by-Step Tutorial

[Last update date: April 17, 2024]

It’s a straightforward process to set up Rust when you have internet access, but what if you’re offline?

Read More