Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.2 is 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 eventual 6.0.0 final release; cargo will not pick up a pre-release tag from raylib = "6.0" alone, so the exact 6.0.0-rc.2 pin 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 a RaylibBuilder. Chain .size() and .title() to configure the window before it opens.
  • .build() opens the window and returns a pair: RaylibHandle (your main API handle) and RaylibThread (a token proving you are on the main thread).
  • rl.begin_drawing(&thread) opens a drawing frame and returns a RaylibDrawHandle. All draw calls live inside this block; the frame is committed when d is dropped at the end of the loop body.
  • Color::WHITE and Color::BLACK are constants in raylib::prelude. No import gymnastics needed.

What’s next