Skip to main content
The Rust Core Library is the dependency-free foundation of the Rust Standard Library. It is the portable glue between the language and its libraries, defining the intrinsic and primitive building blocks of all Rust code.
The core library links to no upstream libraries, no system libraries, and no libc. It is platform-agnostic and minimal by design.

Overview

The core library is minimal: it isn’t even aware of heap allocation, nor does it provide concurrency or I/O. These things require platform integration, and this library is platform-agnostic.

Key Characteristics

  • No dependencies: Links to no external libraries
  • Platform-agnostic: Works across all Rust targets
  • Minimal footprint: Contains only essential primitives
  • No allocation: Doesn’t require heap allocation
  • No I/O: No input/output operations

Core Modules

Language Traits

borrow

Borrowing and ownership traits

clone

The Clone trait for explicit duplication

cmp

Comparison traits: Eq, PartialEq, Ord, PartialOrd

convert

Traits for type conversions: From, Into, TryFrom, TryInto

default

The Default trait for default values

marker

Marker traits: Send, Sync, Copy, Sized

ops

Operator overloading traits

error

The Error trait for error handling

Core Types and Primitives

option

Optional values with Option<T>

result

Error handling with Result<T, E>

array

Fixed-size arrays

slice

Dynamically-sized views into contiguous sequences

str

UTF-8 string slices

char

Unicode scalar values

Memory and Ownership

Core memory functions for working with values:
  • size_of, size_of_val - Size queries
  • swap, replace - Value manipulation
  • drop - Explicit destructor calls
  • forget - Prevent destructors from running
Low-level pointer operations:
  • copy, copy_nonoverlapping - Memory copying
  • write, read - Pointer dereferencing
  • null, null_mut - Null pointer creation
  • Alignment and offset operations
Types for interior mutability patterns:
  • Cell<T> - Shared mutable containers
  • RefCell<T> - Runtime-checked borrowing
  • UnsafeCell<T> - Core primitive for interior mutability
Types for pinning data in memory:
  • Pin<P> - Pointer type that guarantees the pointed-to value won’t move
  • Essential for async/await and self-referential structures

Iteration

iter

Iterator traits and adaptors

async_iter

Async iteration (unstable)

Numeric Types

Signed and unsigned integers:
  • i8, i16, i32, i64, i128, isize
  • u8, u16, u32, u64, u128, usize
Each type provides methods for:
  • Checked arithmetic
  • Saturating arithmetic
  • Wrapping arithmetic
  • Bit manipulation
Floating-point numbers:
  • f16 - 16-bit floating point
  • f32 - 32-bit floating point
  • f64 - 64-bit floating point
  • f128 - 128-bit floating point
Includes mathematical functions like sqrt, sin, cos, etc.

Formatting and Display

Core formatting traits:
  • Display - User-facing output
  • Debug - Programmer-facing output
  • Binary, Octal, Hex - Numeric formatting
  • Used by println!, format!, etc.

Async and Concurrency

future

Asynchronous values with Future trait

task

Task management for async execution

sync

Atomic types and memory ordering

Other Core Functionality

any

Runtime type information

hash

Hashing traits

hint

Compiler hints

intrinsics

Compiler intrinsics

panic

Panic support

time

Duration type

Architecture Support

The arch module provides platform-specific intrinsics and SIMD operations for various architectures including x86, ARM, RISC-V, and more.

SIMD Support

The simd module provides portable SIMD (Single Instruction, Multiple Data) operations:
use core::simd::*;

let a = f32x4::from_array([1.0, 2.0, 3.0, 4.0]);
let b = f32x4::from_array([5.0, 6.0, 7.0, 8.0]);
let sum = a + b;

Usage Requirements

The core library is built on the assumption of a few existing symbols:
  • memcpy, memmove, memset, memcmp, bcmp, strlen
  • These are core memory routines generated by Rust codegen backends
  • Often provided by system libc or compiler-builtins crate
You must define a panic handler using #[panic_handler]:
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}
Required for #![no_std] environments.
rust_eh_personality is used by failure mechanisms. Often mapped to GCC’s personality function. Only called during unwinding.

Common Patterns

Option and Result

// Option for nullable values
fn divide(numerator: f64, denominator: f64) -> Option<f64> {
    if denominator == 0.0 {
        None
    } else {
        Some(numerator / denominator)
    }
}

// Result for error handling
fn parse_version(s: &str) -> Result<u32, ParseError> {
    s.parse().map_err(|_| ParseError)
}

Iterator Usage

let numbers = [1, 2, 3, 4, 5];
let sum: i32 = numbers.iter()
    .filter(|&&x| x % 2 == 0)
    .map(|&x| x * 2)
    .sum();

Interior Mutability

use core::cell::Cell;

struct Counter {
    count: Cell<u32>,
}

impl Counter {
    fn increment(&self) {
        self.count.set(self.count.get() + 1);
    }
}

Stability

The core library has been stable since Rust 1.6.0. It forms the immutable foundation of the Rust language and maintains strict backward compatibility.
  • alloc - Provides heap allocation primitives
  • std - Full standard library built on core and alloc
  • proc_macro - Procedural macro support

Build docs developers (and LLMs) love