#sdl #callback #event-loop #game-loop #api-bindings

no-std sdl3-main

Tools for using SDL's main and callback APIs

14 releases

new 0.6.3 Jun 5, 2026
0.6.2 Mar 26, 2026
0.6.0 Jan 1, 2026
0.6.0-pre-2 Dec 16, 2025
0.1.0 Nov 17, 2024

#30 in No standard library

Download history 305/week @ 2026-02-19 44/week @ 2026-02-26 87/week @ 2026-03-05 89/week @ 2026-03-12 37/week @ 2026-03-19 339/week @ 2026-03-26 1107/week @ 2026-04-02 3381/week @ 2026-04-09 302/week @ 2026-04-16 1150/week @ 2026-04-23 832/week @ 2026-04-30 798/week @ 2026-05-07 425/week @ 2026-05-14 295/week @ 2026-05-21 670/week @ 2026-05-28 2854/week @ 2026-06-04

4,244 downloads per month
Used in 2 crates

Zlib license

4MB
51K SLoC

sdl3-main

This crate provides tools for using SDL 3's main and callback APIs, and for interfacing with the main thread of the process.

SDL main

To provide your own main but call it through SDL, use the main attribute macro. See the documentation for that for more information.

This macro must be called at the root of main.rs in your crate.

Callback API

To use the SDL callback API, you can use either the app_impl attribute macro, or all four of the app_init, app_iterate, app_event and app_quit attribute macros. Don't use the main attribute macro in this mode. See the documentation for more information.

These macros must be called at the root of main.rs in your crate. In the case of app_impl, the impl block for that must be at the root of main.rs, but the rest of the app struct and other impl blocks can be defined elsewhere.

Main thread helpers

Some SDL functions have to be called on the main thread of the process. This crate provides some helper types and functions to alleviate this.

Features

Feature Description
alloc Enable features that require allocation (enabled by default)
std Enable features that require the standard library (enabled by default)
nightly Enable the ? operator to convert Result::Err and Option::None to AppResult*::Failure
use-parking-lot-v0-12 Support parking_lot 0.12 locks in app state accessors

Recent changes

  • 0.6.3:

    • Implement IntoAppResult for bool and Option<bool> so that these can be returned from app_iterate and app_event. For bool, true translates to Continue and false translates to Success. For Option<bool>, Some translates as for bool, and None translates to Failure.
  • 0.6.2:

    • Fix using app_* macros with app states that have generic arguments (all generics have to be known)
  • 0.6.1:

    • Make MainThreadToken::init() safe
    • Fix undefined reference to main_with_result when using the main macro in some cases
  • 0.6.0:

    • Update sdl3-sys to 0.6.0
    • MainThreadToken::init() is no longer necessary in most cases
    • Pass arguments to main on std (!std already did)
    • Add MainThreadData::assert_new/get/get_mut
    • Log error when converting to AppResult*
    • MSRV 1.85

See ChangeLog.md for older changes

Dependencies