Code Explainers

Code explainers tagged #trait-implementation

rust
use std::net::Ipv4Addr;
use std::str::FromStr;
 
#[derive(Debug, Clone, Copy)]

Parsing and matching IPv4 CIDR ranges in Rust

bitwise-operations parsing error-handling
Intermediate 8 steps
rust
use axum::{
    http::{header, StatusCode},
    response::{IntoResponse, Response},
    Json,

Turning errors into RFC 7807 responses in Axum

error-handling enums trait-implementation
Intermediate 7 steps
rust
use std::net::{IpAddr, SocketAddr};
 
use axum::extract::{ConnectInfo, FromRequestParts};
use axum::http::request::Parts;

How a custom ClientIp extractor works in Axum

extractor http-headers proxy-forwarding
Intermediate 8 steps
rust
use std::convert::TryFrom;
 
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HttpStatus {

Converting HTTP codes with TryFrom in Rust

enums error-handling trait-implementation
Intermediate 8 steps
rust
use std::cmp::Ordering;
use std::str::FromStr;
 
#[derive(Debug, Clone, PartialEq, Eq)]

Parsing and ordering semantic versions in Rust

parsing trait-implementation ordering
Intermediate 8 steps
rust
use std::time::Duration;
 
use axum::{
    extract::State,

Rate-limit errors as Axum responses

error-handling rate-limiting http-headers
Intermediate 6 steps
rust
use axum::{
    extract::{FromRef, FromRequestParts},
    http::{request::Parts, StatusCode},
    response::{IntoResponse, Response},

A custom API-key extractor in Axum

authentication extractors trait-implementation
Advanced 8 steps
rust
use std::fmt;
 
#[derive(Debug)]
pub enum ConfigError {

Building a custom error type in Rust

error-handling enums trait-implementation
Intermediate 9 steps
rust
use std::fmt;
 
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Money {

Formatting money with Rust's Display trait

trait-implementation integer-arithmetic enums
Intermediate 10 steps
rust
use std::collections::HashMap;
use std::fmt;
 
#[derive(Debug)]

Parsing a config file with typed errors in Rust

error-handling enums parsing
Intermediate 9 steps
rust
use axum::{
    http::StatusCode,
    response::{IntoResponse, Response},
    Json,

How a custom error type maps to HTTP in Axum

error-handling enums trait-implementation
Intermediate 7 steps
rust
use std::error::Error;
use std::fmt;
 
#[derive(Debug)]

Building a typed error enum in Rust

error-handling enums trait-implementation
Intermediate 9 steps