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"
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.