Quickstart
This chapter gets you from zero to a working window in under 30 lines of Rust. If you have not installed the native build dependencies yet, see the install guide for your platform first.
Add the dependency
In your Cargo.toml:
[dependencies]
raylib = "6.0.0-rc.2"
Note:
6.0.0-rc.2is the published release-candidate of the 6.0 line on crates.io while the canonical merge gets additional review. The headings under this book chapter describe what is shipping in the eventual6.0.0final release; cargo will not pick up a pre-release tag fromraylib = "6.0"alone, so the exact6.0.0-rc.2pin is intentional.
Open a window
extern crate raylib;
use raylib::prelude::*;
fn main() {
let (mut rl, thread) = raylib::init()
.size(640, 480)
.title("Hello, raylib-rs")
.build();
while !rl.window_should_close() {
let mut d = rl.begin_drawing(&thread);
d.clear_background(Color::WHITE);
d.draw_text("Hello, raylib-rs!", 20, 20, 20, Color::BLACK);
}
}
Walking through the code:
raylib::init()returns aRaylibBuilder. Chain.size()and.title()to configure the window before it opens..build()opens the window and returns a pair:RaylibHandle(your main API handle) andRaylibThread(a token proving you are on the main thread).rl.begin_drawing(&thread)opens a drawing frame and returns aRaylibDrawHandle. All draw calls live inside this block; the frame is committed whendis dropped at the end of the loop body.Color::WHITEandColor::BLACKare constants inraylib::prelude. No import gymnastics needed.