Fundamentals and Core Concepts
Reading from Standard Input
use std::io::{self, BufRead};
fn main() -> io::Result<()> {
let stdin = io::stdin();
let mut lines = 0; …
64 articles about rust development, tools, and best practices
use std::io::{self, BufRead};
fn main() -> io::Result<()> {
let stdin = io::stdin();
let mut lines = 0; …
The factory method pattern provides an interface for creating objects:
trait Animal {
fn make_sound(&self) -> &str;
} …
use thiserror::Error;
use std::path::PathBuf;
#[derive(Error, Debug)]
enum FileError {
#[error("File not found: …
With Rust 2018, the module system was simplified. You can now use the following structure:
src/
├── …
Read Article →
These optimizations focus on making the most efficient use of CPU and memory:
For CPU-intensive tasks, you can use the rayon
crate for parallel processing:
use rayon::prelude::*;
use std::path::{Path, …
The type-state pattern encodes state transitions in the type system:
// States
struct Idle;
struct Running;
struct Paused;
struct …
use std::process;
use thiserror::Error;
use clap::Parser;
#[derive(Error, Debug)]
enum CliError {
#[error("I/O …
Unit tests are typically placed in the same file as the code they test, in a module annotated with #[cfg(test)]
:
// src/lib.rs
pub fn add …
use rayon::prelude::*;
use std::time::Instant;
// Sequential implementation
fn sum_of_squares_sequential(data: &[ …
Let’s start with a basic command-line application that accepts arguments and prints output:
use …
Rust’s ownership system influences how we manage resources:
RAII is a …
Read Article →