Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.
Scope and conventions
TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.
println! adds a newline; print! does not. format! returns a String. {:?} uses Debug formatting, which quotes/escapes a string. to_owned() turns borrowed text into owned text.
Fragment
Fragment inside a function.
src/main.rs
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let name = "north";let text = format!("item: {name}");println!("{text:?}");
{} formats a value; {name} captures a local name. A colon introduces formatting options such as precision, alignment or zero padding. Formatting returns or prints text, depending on the macro.
Fragment
Independent fragments inside a function.
src/main.rs
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let price = format!("{:.1}", 6.2);let tag = format!("{:>4}", "x");
read_line appends to a String, retaining LF (and CR when present). Success returns the byte count; zero means EOF. ? propagates an I/O error. Clear a reused buffer when appropriate.
Fragment
Complete program; reads once.
src/main.rs
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
use std::io;fn main() -> io::Result<()> { let mut text = String::new(); let bytes = io::stdin().read_line(&mut text)?; println!("{bytes}"); Ok(())}
parse::<T>() chooses the target type and returns Result. Integer parsing rejects surrounding whitespace and trailing junk; signed and unsigned target types accept different ranges.
Fragment
Independent fragment inside a function.
src/main.rs
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let result = "24".parse::<i32>();match result { Ok(n) => println!("{n}"), Err(error) => eprintln!("{error}"),}
Read::read fills a byte buffer and returns a count; zero with a nonempty buffer signals EOF. from_utf8 validates bytes; expect panics on failure. A byte chunk can split UTF-8; arbitrary text requires retaining incomplete UTF-8 sequences across reads.
Fragment
Single-read demonstration; repeated reads need an explicit decoding/record boundary policy.
src/main.rs
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
use std::io::{self, Read};fn main() -> io::Result<()> { let mut input = io::stdin().lock(); let mut buffer = [0_u8; 8]; let n = input.read(&mut buffer)?; println!("{:?}", &buffer[..n]); Ok(())}