<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://johnwick.cc/index.php?action=history&amp;feed=atom&amp;title=How_Rust%E2%80%99s_Target-Independent_Core_Works</id>
	<title>How Rust’s Target-Independent Core Works - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://johnwick.cc/index.php?action=history&amp;feed=atom&amp;title=How_Rust%E2%80%99s_Target-Independent_Core_Works"/>
	<link rel="alternate" type="text/html" href="https://johnwick.cc/index.php?title=How_Rust%E2%80%99s_Target-Independent_Core_Works&amp;action=history"/>
	<updated>2026-05-06T17:55:49Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.1</generator>
	<entry>
		<id>https://johnwick.cc/index.php?title=How_Rust%E2%80%99s_Target-Independent_Core_Works&amp;diff=100&amp;oldid=prev</id>
		<title>PC: Created page with &quot;There’s a moment every Rust developer has: You’re writing code for a tiny embedded board, or compiling to WebAssembly, or even booting Rust on bare metal… and you realize: “Wait. I have no OS, no allocator, no threads…  So how the hell is Rust still working?” The answer is the core crate — Rust’s target-independent standard library. It is the smallest, most portable piece of the entire language, and honestly, one of the most beautiful pieces...&quot;</title>
		<link rel="alternate" type="text/html" href="https://johnwick.cc/index.php?title=How_Rust%E2%80%99s_Target-Independent_Core_Works&amp;diff=100&amp;oldid=prev"/>
		<updated>2025-11-15T16:37:20Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;There’s a moment every Rust developer has: You’re writing code for a tiny embedded board, or compiling to WebAssembly, or even booting Rust on bare metal… and you realize: “Wait. I have no OS, no allocator, no threads…  So how the hell is Rust still working?” The answer is the core crate — Rust’s target-independent standard library. It is the smallest, most portable piece of the entire language, and honestly, one of the most beautiful pieces...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;There’s a moment every Rust developer has: You’re writing code for a tiny embedded board, or compiling to WebAssembly, or even booting Rust on bare metal… and you realize:&lt;br /&gt;
“Wait. I have no OS, no allocator, no threads… &lt;br /&gt;
So how the hell is Rust still working?”&lt;br /&gt;
The answer is the core crate — Rust’s target-independent standard library. It is the smallest, most portable piece of the entire language, and honestly, one of the most beautiful pieces of software engineering in Rust.&lt;br /&gt;
&lt;br /&gt;
This article goes deep into:&lt;br /&gt;
* 		How core works without an OS&lt;br /&gt;
* 		How it avoids allocations&lt;br /&gt;
* 		How formatting, slices, iterators, and results exist without std&lt;br /&gt;
* 		How the compiler treats core specially&lt;br /&gt;
* 		Why core is the foundation for embedded, WASM, and kernels&lt;br /&gt;
* 		Architecture diagrams, code flows, internals, and real examples&lt;br /&gt;
&lt;br /&gt;
And yes — fully human-written, fully technical, and emotionally honest.&lt;br /&gt;
Why core Even Exists&lt;br /&gt;
&lt;br /&gt;
Rust has three “layers” of libraries:&lt;br /&gt;
core   →   alloc   →   std&lt;br /&gt;
&lt;br /&gt;
Think of them like this:&lt;br /&gt;
* 		core — no OS, no heap, just pure language primitives.&lt;br /&gt;
* 		alloc — adds heap-backed containers, uses an allocator.&lt;br /&gt;
* 		std — adds OS features like threads, sockets, files.&lt;br /&gt;
&lt;br /&gt;
core is the only layer guaranteed to work everywhere, even here:&lt;br /&gt;
✔ A bootloader ✔ An STM32 microcontroller ✔ A browser running WebAssembly ✔ A custom kernel ✔ A GPU shader runtime ✔ A Raspberry Pi with no Linux&lt;br /&gt;
&lt;br /&gt;
Without core, Rust would be just a compiler classroom experiment.&lt;br /&gt;
With core, Rust becomes a systems language.&lt;br /&gt;
What’s Actually Inside core?&lt;br /&gt;
&lt;br /&gt;
Here’s the funny part:&lt;br /&gt;
You use core every day — you just call it by other names.&lt;br /&gt;
&lt;br /&gt;
| Feature You Use                      | Actually Lives In          |&lt;br /&gt;
| ------------------------------------ | -------------------------- |&lt;br /&gt;
| `Option&amp;lt;T&amp;gt;`                          | `core::option`             |&lt;br /&gt;
| `Result&amp;lt;T, E&amp;gt;`                       | `core::result`             |&lt;br /&gt;
| Iterators                            | `core::iter`               |&lt;br /&gt;
| `&amp;amp;[T]`, `&amp;amp;str`                       | `core::slice`, `core::str` |&lt;br /&gt;
| Traits like `Copy`, `Clone`, `Sized` | `core::marker`             |&lt;br /&gt;
| Arithmetic ops                       | `core::ops`                |&lt;br /&gt;
| Pointers                             | `core::ptr`                |&lt;br /&gt;
| Panics                               | `core::panicking`          |&lt;br /&gt;
| `format_args!`                       | `core::fmt`                |&lt;br /&gt;
&lt;br /&gt;
This is shocking the first time you see it. All these everyday tools don’t require an OS or heap.&lt;br /&gt;
A Peek at core’s File Layout&lt;br /&gt;
&lt;br /&gt;
Here’s a simplified view of the internals:&lt;br /&gt;
&lt;br /&gt;
core/&lt;br /&gt;
 ├── alloc/              (NOT heap allocation — core uses static alloc only)&lt;br /&gt;
 ├── array/&lt;br /&gt;
 ├── char/&lt;br /&gt;
 ├── cmp/&lt;br /&gt;
 ├── convert/&lt;br /&gt;
 ├── fmt/                &amp;lt;— formatting engine&lt;br /&gt;
 ├── future/&lt;br /&gt;
 ├── hint/&lt;br /&gt;
 ├── intrinsics/         &amp;lt;— compiler magic hooks&lt;br /&gt;
 ├── iter/&lt;br /&gt;
 ├── mem/&lt;br /&gt;
 ├── num/&lt;br /&gt;
 ├── ops/&lt;br /&gt;
 ├── option/&lt;br /&gt;
 ├── panic/&lt;br /&gt;
 ├── ptr/&lt;br /&gt;
 ├── result/&lt;br /&gt;
 ├── slice/&lt;br /&gt;
 └── str/&lt;br /&gt;
&lt;br /&gt;
Every part is designed to work with:&lt;br /&gt;
* 		no OS&lt;br /&gt;
* 		no heap&lt;br /&gt;
* 		no system calls&lt;br /&gt;
* 		no global allocator&lt;br /&gt;
* 		no threads&lt;br /&gt;
* 		no I/O&lt;br /&gt;
&lt;br /&gt;
This is what makes core the “portable soul” of Rust.&lt;br /&gt;
How core Works Without Allocation&lt;br /&gt;
&lt;br /&gt;
Let’s take something we all use:&lt;br /&gt;
&lt;br /&gt;
let s = [1, 2, 3];&lt;br /&gt;
s.iter().map(|x| x + 1);&lt;br /&gt;
&lt;br /&gt;
How does .map() exist without allocation?&lt;br /&gt;
Because iterators are lazy, and laziness costs zero memory.&lt;br /&gt;
This is core’s philosophy:&lt;br /&gt;
“Provide tools that need no heap, only the stack.”&lt;br /&gt;
&lt;br /&gt;
Example: core::iter::Map is just:&lt;br /&gt;
&lt;br /&gt;
pub struct Map&amp;lt;I, F&amp;gt; {&lt;br /&gt;
    iter: I,&lt;br /&gt;
    f: F,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
That’s it. Just two fields on the stack.&lt;br /&gt;
&lt;br /&gt;
When you do:&lt;br /&gt;
let x = arr.iter().map(|x| x + 1);&lt;br /&gt;
&lt;br /&gt;
No memory allocated. No data created.&lt;br /&gt;
You’ve just built a little struct with two fields.&lt;br /&gt;
How core Handles Formatting Without I/O&lt;br /&gt;
println! lives in std — it needs I/O.&lt;br /&gt;
&lt;br /&gt;
But format_args! lives in core.&lt;br /&gt;
Wait — formatting with no printing?&lt;br /&gt;
Here’s what’s happening:&lt;br /&gt;
format_args!(&amp;quot;hi {}&amp;quot;, 5)&lt;br /&gt;
&lt;br /&gt;
Expands to something like:&lt;br /&gt;
Arguments {&lt;br /&gt;
    pieces: &amp;amp;[&amp;quot;hi &amp;quot;, &amp;quot;&amp;quot;],&lt;br /&gt;
    args: &amp;amp;[5],&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
It’s just a structured description of formatting.&lt;br /&gt;
core doesn&amp;#039;t print anything. It just builds an IR (intermediate representation).&lt;br /&gt;
Why?&lt;br /&gt;
&lt;br /&gt;
Because the compiler uses it for:&lt;br /&gt;
* 		panic messages&lt;br /&gt;
* 		formatting inside alloc::format!&lt;br /&gt;
* 		debug derives&lt;br /&gt;
* 		errors inside no-std environments&lt;br /&gt;
&lt;br /&gt;
Zero I/O. Zero heap. Zero runtime.&lt;br /&gt;
How core’s Intrinsics Work (Compiler Magic)&lt;br /&gt;
&lt;br /&gt;
Deep inside core::intrinsics are functions that only the compiler can call, for example:&lt;br /&gt;
&lt;br /&gt;
fn copy_nonoverlapping&amp;lt;T&amp;gt;(src: *const T, dst: *mut T, count: usize);&lt;br /&gt;
&lt;br /&gt;
These become LLVM instructions:&lt;br /&gt;
memcpy&lt;br /&gt;
memmove&lt;br /&gt;
abort&lt;br /&gt;
unreachable&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
Rust’s slice indexing is implemented using intrinsics:&lt;br /&gt;
&lt;br /&gt;
#[inline]&lt;br /&gt;
pub unsafe fn get_unchecked(&amp;amp;self, index: usize) -&amp;gt; &amp;amp;T {&lt;br /&gt;
    &amp;amp;*self.as_ptr().add(index)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
And LLVM turns this into a real pointer math operation, even on WASM or embedded.&lt;br /&gt;
How core Provides Panic Support Without std&lt;br /&gt;
&lt;br /&gt;
You might think panics need:&lt;br /&gt;
* 		strings&lt;br /&gt;
* 		stdout&lt;br /&gt;
* 		printing&lt;br /&gt;
* 		unwinding&lt;br /&gt;
&lt;br /&gt;
But core provides the minimal interface:&lt;br /&gt;
#[panic_handler]&lt;br /&gt;
fn panic(_info: &amp;amp;PanicInfo) -&amp;gt; ! {&lt;br /&gt;
    loop {}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
This is why in embedded Rust you often see:&lt;br /&gt;
&lt;br /&gt;
#[panic_handler]&lt;br /&gt;
fn panic(_info: &amp;amp;PanicInfo) -&amp;gt; ! {&lt;br /&gt;
    cortex_m::asm::bkpt();&lt;br /&gt;
    loop {}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
core doesn’t care what the panic does. It just provides the structure (PanicInfo). The platform decides what to do.&lt;br /&gt;
Architecture of core (ASCII Diagram)&lt;br /&gt;
&lt;br /&gt;
                 ┌──────────────────────────┐&lt;br /&gt;
                 │         rustc            │&lt;br /&gt;
                 └─────────────┬────────────┘&lt;br /&gt;
                               │&lt;br /&gt;
                               ▼&lt;br /&gt;
          ┌────────────────────────────────────┐&lt;br /&gt;
          │             core crate             │&lt;br /&gt;
          │────────────────────────────────────│&lt;br /&gt;
          │  primitives: Option, Result        │&lt;br /&gt;
          │  pointer types                     │&lt;br /&gt;
          │  slices, str, iterators            │&lt;br /&gt;
          │  no heap, no OS                    │&lt;br /&gt;
          └─────────────────┬──────────────────┘&lt;br /&gt;
                            │&lt;br /&gt;
         ┌──────────────────┼─────────────────┐&lt;br /&gt;
         ▼                  ▼                 ▼&lt;br /&gt;
   embedded targets   wasm32-unknown    custom kernels&lt;br /&gt;
&lt;br /&gt;
Real Example: Option&amp;lt;T&amp;gt; Implementation in core&lt;br /&gt;
You use it daily.&lt;br /&gt;
&lt;br /&gt;
Here’s how insanely simple it really is:&lt;br /&gt;
pub enum Option&amp;lt;T&amp;gt; {&lt;br /&gt;
    None,&lt;br /&gt;
    Some(T),&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
But the magic is in zero-cost optimizations.&lt;br /&gt;
For example, Option&amp;lt;&amp;amp;T&amp;gt; is stored in one pointer:&lt;br /&gt;
* 		None is represented as null&lt;br /&gt;
* 		Some(ptr) is literally the pointer&lt;br /&gt;
&lt;br /&gt;
No overhead. No extra bytes. No runtime work.&lt;br /&gt;
Rust’s niche optimizations are implemented directly inside core.&lt;br /&gt;
&lt;br /&gt;
Real Example: &amp;amp;str in core&lt;br /&gt;
&amp;amp;str is two fields:&lt;br /&gt;
&lt;br /&gt;
pub struct Str {&lt;br /&gt;
    ptr: *const u8,&lt;br /&gt;
    len: usize,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
String indexing, slicing, and UTF-8 validation all live inside core.&lt;br /&gt;
And the compiler inlines almost everything:&lt;br /&gt;
&lt;br /&gt;
let s = &amp;quot;hello&amp;quot;;&lt;br /&gt;
let h = &amp;amp;s[0..1];  // core::str::slice_error checks&lt;br /&gt;
&lt;br /&gt;
In optimized builds, Rust removes slice checks when it can prove safety.&lt;br /&gt;
How core Enables no_std Ecosystems&lt;br /&gt;
&lt;br /&gt;
Embedded Rust is possible because core gives developers:&lt;br /&gt;
* 		iter&lt;br /&gt;
* 		Option, Result&lt;br /&gt;
* 		pointer APIs&lt;br /&gt;
* 		formatting IR&lt;br /&gt;
* 		numeric traits&lt;br /&gt;
* 		cell types&lt;br /&gt;
* 		slices &amp;amp; byte manipulation&lt;br /&gt;
&lt;br /&gt;
You can write a complete I2C driver, RTOS, or microkernel using only:&lt;br /&gt;
#![no_std]&lt;br /&gt;
&lt;br /&gt;
That line means:&lt;br /&gt;
use core;&lt;br /&gt;
not use std;&lt;br /&gt;
&lt;br /&gt;
Everything still works — because core is all Rust really needs.&lt;br /&gt;
Code Flow: How Your Rust Program Uses core&lt;br /&gt;
Here’s the surprising truth:&lt;br /&gt;
&lt;br /&gt;
Even when you use std, your program internally depends on core.&lt;br /&gt;
&lt;br /&gt;
your code&lt;br /&gt;
   ↓&lt;br /&gt;
std (uses alloc)&lt;br /&gt;
   ↓&lt;br /&gt;
alloc (uses core)&lt;br /&gt;
   ↓&lt;br /&gt;
core (depends only on compiler)&lt;br /&gt;
   ↓&lt;br /&gt;
rustc/LLVM&lt;br /&gt;
   ↓&lt;br /&gt;
machine code&lt;br /&gt;
&lt;br /&gt;
core is the only crate that rustc treats as a language primitive.&lt;br /&gt;
Everything else — even std — is just a library.&lt;br /&gt;
Why core Matters for the Future of Rust&lt;br /&gt;
&lt;br /&gt;
The world is moving toward:&lt;br /&gt;
* 		WASM without JavaScript&lt;br /&gt;
* 		tiny IoT hardware&lt;br /&gt;
* 		edge compute&lt;br /&gt;
* 		unikernels&lt;br /&gt;
* 		WASI-as-the-new-OS&lt;br /&gt;
* 		Rust inside firmware + bootloaders&lt;br /&gt;
&lt;br /&gt;
All of these require a language that can work with:&lt;br /&gt;
* 		No malloc&lt;br /&gt;
* 		No threads&lt;br /&gt;
* 		No filesystem&lt;br /&gt;
* 		No OS&lt;br /&gt;
&lt;br /&gt;
Most languages simply cannot operate in that world.&lt;br /&gt;
Rust can — because core exists.&lt;br /&gt;
core is the “Rust DNA”: &lt;br /&gt;
The minimal blueprint needed to express ownership, slices, pointers, traits, and control flow anywhere.&lt;br /&gt;
Final Thoughts (Human, Emotional)&lt;br /&gt;
&lt;br /&gt;
The core crate is one of the most beautiful parts of Rust.&lt;br /&gt;
It represents the language distilled to its pure form — no OS, no fancy runtime, no threading model, no heap. Just the essence:&lt;br /&gt;
* 		predictable memory&lt;br /&gt;
* 		zero-cost abstractions&lt;br /&gt;
* 		safe pointers&lt;br /&gt;
* 		move semantics&lt;br /&gt;
* 		powerful algebraic types&lt;br /&gt;
&lt;br /&gt;
When you look at core, you’re not just looking at Rust’s internals. You’re looking at what makes Rust portable, safe, and honestly, timeless.&lt;br /&gt;
Every blinking LED on an STM32 board, every WASM module sent to a browser, every bootloader written in Rust — they all owe their existence to the quiet brilliance of the core crate.&lt;br /&gt;
&lt;br /&gt;
It’s the foundation nobody sees, but everyone relies on.&lt;br /&gt;
And that’s the kind of engineering that deserves respect.&lt;/div&gt;</summary>
		<author><name>PC</name></author>
	</entry>
</feed>