New to Rust
New to Rust, welcome. I will explain each word the first time it appears, and I will tell you when something is not built yet.
RustClamp is the application composition layer for Rust. A layer of what? It sits above the libraries other programmers use for the web, databases and messaging, such as Axum, SQLx, Tokio and NATS, and puts them together into one application. It does not replace them.
Where would you like to start: what this is, how much Rust you need, or the smallest program?
- I am pretty new to Rust, so what is RustClamp, in plain words, please?
RustClamp is the application composition layer for Rust. A layer of what? It sits above the libraries other programmers use for the web, databases and messaging, such as Axum, SQLx, Tokio and NATS, and puts them together into one application. It does not replace any of them.
You begin with a tiny program and add pieces only when the application needs them, such as commands, web pages, a database, background jobs or a timer. The program stays yours, and Clamp just helps the pieces fit together.
You will see two names. RustClamp is the project and its website, and Clamp is what you use in your code, which is why the command is called
clamp. I will say Clamp from here on.It is also young: it started in September 2026 and is experimental. That matters for how you use it, and I mention it now because a beginner deserves to know before picking a tool.
- I keep hearing the word framework. Is RustClamp a framework, or something else?
Good question, and the honest answer is: not in the usual sense. A framework usually decides the shape of your whole program and often wraps the libraries you use. Clamp does neither.
It is a composition layer. Picture the pieces of an application, such as a clock, a web server and a database connection, each doing its own job. Clamp describes what each piece needs and offers, and checks that they fit together before the program starts.
It does have a friendly front door, a crate called the facade that you add to a project, and some conveniences for websites. But the core idea is composition, and the smallest program uses none of it.
In everyday terms, a library is a box of tools you pick up when you need them, and a framework also tells you where the workbench goes. Clamp stays on the toolbox side of that line, and it never moves your workbench.
- Is this one of those drag-and-drop website builders where I click things together?
No, and it is worth being clear about that. There is nothing visual here. You write Rust in a text editor.
You can build a website or an API with it, and there is a generator for one, but the result is an ordinary Rust project you read and change.
If you have used a site builder with templates and drag handles, you will notice the difference quickly. Here every change is a change to text files that you own.
clamp init my-site --webThere is a generator that writes a starter web project, but the result is Rust files and a frontend folder to edit. Treat it as a head start for programmers, not as a shortcut around learning.
- Do I have to learn all of Rust before I can even try RustClamp?
No, but you do need some. If
fn main(), astructand acargo runare still strange, spend a few evenings with the official Rust book first, because I would be teaching you Rust badly.Once you can write a small Rust program, Clamp is learnable one concept at a time. Hello Clamp needs nothing more than that.
A reasonable bar is this: you can write a small program that reads some input and prints something, and you know what
cargo rundoes. If that is not true yet, finish a beginner course first. This guide will still be here.I say that because Clamp does not hide Rust from you. When something goes wrong you will be reading ordinary Rust errors, and no tool can soften that.
- Alright, so what do I need to install on my computer to try it?
Rust 1.96.1 or newer, and the
clampcommand, which creates and runs projects. On Linux or macOS one line installs both, and it installs Rust first if it is missing.Windows users can go through WSL. The installer downloads a prebuilt
clampand checks its SHA-256 checksum before using it.If you would rather not pipe a script into
bash, and plenty of people prefer not to, you can read the script first at that address. Or you can buildclampyourself from a source checkout.cargo install --path rustclamp/toolingOn Linux x86_64 and on macOS you get a prebuilt binary. On other platforms the installer builds it from source, which takes longer.
curl -fsSL https://rustclamp.com/install.sh | bash- Could you show me the smallest possible program written with RustClamp, please?
This is the whole thing. The part after
||is a closure, which is a small unnamed function.Clamp::runcalls it once and hands back whatever it returns.That is all it does at this size. No hidden setup, no background threads.
Notice what is not there. No main loop, no setup call, no configuration file. In plain Rust you would write the same
println!straight insidefn main, and the output would be identical.The reason to use
Clamp::runat all is that this is the door every later piece of Clamp comes through. Right now it is a doorway with nothing in it, and that is on purpose.use rustclamp::prelude::*; fn main() { Clamp::run(|| { println!("Hello Clamp"); }); }- You mentioned a closure there. What exactly is a closure in Rust, anyway?
You just met one in the smallest program. A closure is a function you can write inline and pass around. The vertical bars hold its parameters, and here there are none, so it is just
||.You will meet closures everywhere in Rust. If this one is your first, that is fine: the rest of this guide mostly uses named functions and structs.
Closures can also remember things from around them. That is how
Clamp::runlets your code borrow local data without special rules, which you will notice when programs get bigger.- Okay, how do I actually run that program on my own machine?
Now that you have seen the program, running it takes about a minute. Three commands.
clamp initwrites a new project, andcargo runis the normal Rust way to build and start it. You should see the greeting printed in your terminal.The project name has to start with a letter and use only letters, digits, dashes or underscores.
The first build takes a moment because Cargo downloads and compiles the Clamp facade from Git. Later runs are fast, since only your own code is rebuilt.
If a command fails, the usual reasons are that Rust is not installed or that the compiler is too old, since Clamp wants 1.96.1 or newer.
clamp init hello-clamp cd hello-clamp cargo run- What did that clamp init command just write into my project folder?
That is the project we just created, so let me open it up. A normal Cargo project.
src/main.rshas the one-liner below, andCargo.tomlpoints at therustclampcrate through its public Git repository.It reaches for Git because the packages are not on crates.io yet. The project also gets its own empty
[workspace]table, so it never changes some other workspace around it.The empty
[workspace]table is a small courtesy. Without it, Cargo might decide your new project belongs to some bigger project in a parent folder and reconfigure things.It is your project from the first second, so open
src/main.rsand change the message to see the output change.Clamp::run(|| println!("Hello from Clamp!"));- Why can I not just add it to my project with cargo add rustclamp?
Not yet. The crates are marked unpublished while registry ownership and the early API are reviewed, so for now
clamp initwrites the Git dependency for you. The open work is tracked here.This is one reason I call Clamp early-stage, and I would rather you hear it from me now.
In practice this changes little for learning. Cargo records the exact commit in
Cargo.lockthe first time you build, so your project stays on that version until you choose to update it.- So is it actually safe for me to learn on, given that it is so new?
Learning, yes. Betting your job on it, not yet. RustClamp is experimental, it started in September 2026, and its APIs may change before 1.0.
If you are new to Rust, you will learn the same Rust either way, so nothing you pick up here is wasted. Just do not build your only business on it this month.
Concretely, expect two things. Some names and shapes will change between versions, and some features described as planned simply do not exist yet. Neither should stop you following the examples, since each is tested together with the version it ships with.
For a learner the risk is mostly annoyance, and not wasted effort. The ideas you pick up, like passing things in and testing with stand-ins, are worth knowing whatever happens to Clamp.
- You keep saying capabilities. Can you explain that word to me without any jargon?
A capability is something the program can do or use, described by its shape and not by who provides it. Telling the time is the first one Clamp defines, called
Clock.Look at the greeter below.
C: Clockreads as "any type that can tell time". The greeter never calls the system clock itself, so you decide what clock it gets.The word comes from a simple shift. Instead of saying "I need the system clock", the greeter says "I need something that can tell time". That is what lets a test, a simulation and a real program all use the same greeter.
Clamp's own first capability is exactly this one. Later ones include a message bus, and I will tell you which exist and which are only planned when we get there.
impl<C: Clock> Greeter<C> { pub fn new(clock: C) -> Self { Self { clock } } pub fn greet(&self, name: &str) -> String { let seconds = self .clock .now() .duration_since(UNIX_EPOCH) .unwrap_or_default() .as_secs(); format!("Hello, {name}! (unix second {seconds})") } }- Why would I hand the program a clock instead of just asking the system for the time?
This is the same greeter we just looked at. Because a test cannot control the system clock, and a test that depends on "now" tends to fail on a Tuesday. If the greeter is handed its clock, a test can hand it one frozen at second 42.
The test below does exactly that and expects exactly that answer. That one habit of passing things in is most of what capabilities are about.
Notice the test needed no special tool.
FixedClockis a few lines of ordinary Rust you could write yourself, and Core also ships a ready-madeManualClockwhose time you move withadvance.let clock = ManualClock::new(UNIX_EPOCH);The same trick works for anything that changes between runs, such as random numbers, files or the network. You hand the code a stand-in and it never knows the difference.
struct FixedClock(SystemTime); impl Clock for FixedClock { fn now(&self) -> SystemTime { self.0 } }- Okay, and what is a module in Clamp? Is that the same as a Rust module?
Following on from the clock we just passed in. A module is a named piece of your application that says what it needs and what it offers. The line below says "the greeter module needs a clock", and nothing else.
A part called Kernel reads those declarations and matches needs to offers. You can ignore all of this until your program has more than a couple of pieces.
A Rust module, the thing you make with
mod, just organises files and names. A Clamp module shares the word but is a different idea: a named piece with declared needs, so tools can draw a map of your program.impl Module for GreeterModule { const ID: ModuleId = GREETER_MODULE; }You can write Clamp programs for a long while without declaring any, because the smallest examples do not need them.
impl Requires<ClockCapability> for GreeterModule {}- Will the error messages scare me off while I am still learning all this?
Rust compiler errors will, now and then, and Clamp does not change that. What Clamp adds is its own named errors for wiring mistakes: a missing provider names the module and the capability, and two providers for one need are listed side by side.
That part is a prototype, so expect the wording to improve. Honest summary: kinder than a stack trace, not yet a hand to hold.
Resolution errors come back as a value you can print. They say which kind of failure happened, which module asked, which capability it asked for, and who the candidates were. The four kinds are listed below.
MissingProvider, AmbiguousProviders, ProviderSelectionUnavailable, UndeclaredRequirement,In plain terms, a missing provider says nobody offers this, and ambiguous says two things offer it and you did not pick. Both are fixed by editing one declaration.
- What order would you suggest I learn all of this in, one step at a time?
Follow the tree on the site: Hello Clamp, then configuration, then a command, then a web page, then a background worker. Each step is a runnable example, and you only move on when the last one makes sense.
Skip the middle if you are impatient. Nothing breaks if you read the web step before the module step.
The order matters less than staying on runnable ground. If you can run an example and change one line, you are learning, even if you skip ahead.
Configuration is the first stop after Hello, and it is gentler than it sounds: settings come from a text file and the environment.
- Once I know more, what kinds of things could I actually build with it?
Command-line tools, web sites and APIs, background workers, scheduled jobs and even a simulated device loop. Not all at once, and not today.
My suggestion is to pick the smallest one that you actually want to use yourself. A tool you need beats an example you do not.
clamp init <project-name> [--blank|--app|--web|--tui|--package]A good beginner target is a small command-line tool. The generated project for it is about a dozen lines and needs nothing else installed. After that, a tiny web page is a natural next step.
Things like a payment system or a store come later, if ever, and I would be wary of any tutorial that starts there.
- You keep saying cargo run. What is Cargo, and do I need to learn it?
Cargo is Rust's build tool and package manager, and it comes with Rust itself. It compiles your program, downloads the libraries it depends on, runs your tests and starts the result.
A Clamp project is an ordinary Cargo project. The file
Cargo.tomllists what it depends on, and for now that includes the Clamp facade, fetched from Git.You need only three commands at first:
cargo runbuilds and starts,cargo testruns tests, andcargo checkreports errors without building the full program.Clamp forwards them for convenience, so
clamp testpasses your arguments straight through to Cargo.clamp test- Everyone says Clock is a trait, and I do not know what that word means.
A trait is a promise about behaviour. A type that implements a trait promises it has certain methods, and code can then say: give me anything that keeps that promise.
Clockmakes one promise, anowmethod that returns the current time. A real clock keeps it by asking the system, and a fixed clock keeps it by returning a stored value.pub trait Clock: Send + Sync {That is why the greeter could accept either without caring. If you have met the word interface in another language, a trait is Rust's closest relative.
Clamp's
Clockalso requiresSend + Sync, which in plain words means a clock can be shared between threads safely. You can ignore that until you work with threads.- Can I change the hello program and see what happens, without breaking anything?
Yes, and it is the best way to learn. Open
src/main.rs, change the text inside the quotes, then runcargo runagain.You can also make the closure produce a value.
Clamp::runhands back whatever the closure returns, so you can use it later in your program.let n = Clamp::run(|| 2 + 2); println!("{n}");The tests for this behaviour check that the closure runs once on the calling thread, and that errors and panics come back untouched. There is not much here you can break.
When you want something bigger, the next idea is capabilities.
- What do I do if I get stuck, or the program will not compile?
First, read the error from the top. Rust error messages usually point at the exact line and often suggest a fix, and they are the same ones every Rust programmer reads.
Second, use the examples as a map. There are fourteen of them, each with a command that runs it, and most have tests, so you can compare a working version with yours.
cargo test --offline --locked --manifest-path examples/a1-capability/Cargo.tomlThird, the project's issues are public on GitHub, and that is where unfinished or confusing parts get recorded. This is early software, so sometimes the answer is that a thing is not built yet.
- You mentioned configuration earlier. What does that mean for a beginner like me?
Configuration means settings that can change without changing the code, such as a name, a port number or how many emails you allow per day. You keep them in a text file called
.envand in your computer's environment.Clamp's
Configreads both. If the same setting appears in both places, the real environment wins, which lets a server override a file on your laptop.let config = Config::parse("APP_NAME=Site\nMAIL_PER_DAY=100\n"); assert_eq!(config.get_or("MAIL_PER_DAY", 50), 100);You ask for a value and give a default for when it is missing, and Clamp reads it as the type of that default. A value that is present but is not a number, when you asked for a number, stops the program at startup and names the key.
- Why Rust at all? Would I not be better off with an easier language?
It depends what you want. Rust is harder to learn than many languages, and anyone who tells you otherwise is selling something.
In return it produces fast programs, and the compiler catches many mistakes before the program runs. Clamp is built for people who have chosen Rust and want help organising a growing application.
If you have not chosen Rust yet, you do not need Clamp. Learn the language first, and if it suits you, come back, because the next steps will make more sense then.