An SDL (3.4) & SDL_ttf (3.2) Rust wrapper. Expect many breaking changes between each release.
It's somewhere between raw sdl3-sys bindings, and a higher-level graphics framework with a radically different API. The general plan is:
- expose the functionality of SDL,
- minimize ways to shoot yourself in the foot.
Important
This crate isn't concerned with how you find, and link with, SDL and its satellite libraries on your system. These topics are better covered by the sdl3-sys docs.
Note
Functions and methods usually map 1:1 to their SDL counterparts in terms of functionality
(in such cases, there is always a corresponding #[doc(alias = "...")] attribute).
There is an effort to "pluck" documentation from the SDL wiki and map it to Rust abstractions,
while preserving the meaning. The first pass has been done via LLMs, so there may be some slop.
Most, but not all, functionality requires two things from the init module to be in scope:
init::Context- a relevant subsystem
- for example,
init::VideoforWindow::new
- for example,
Since SDL works with opaque pointers, using Rust references would cause unnecessary double indirection. To avoid this, Sandlot uses custom types with matching properties. For example:
- a
Textureis an owned object which willDropthe underlying handle upon going out of scope Ref<'a, Texture>andRefMut<'a, Texture>mimic&Textureand&mut Texture- these can be obtained from an owned object via the
as_ref()method - the only difference between these two is that
Refonly implementsDereffor its handle, whileRefMutalso implementsDerefMut
- these can be obtained from an owned object via the
- a
TextureHandleis analogous to a pointer. It exposes all methods, but is not lifetime-bound to anything
Allocations originating from SDL are wrapped in a custom implementation of Box and String.
These might not have exact 1:1 semantics with their Rust counterparts; check documentation for specifics.
In an attempt to justify the time spent on this project, here is a list of things that, in my eyes, make Sandlot much neater to use over raw SDL bindings:
Dropimpl'd where applicable1Reffor borrowing opaque handles without extra indirectionsandlot::Result<T>instead ofSDL_GetError()BoxandStringfor mapping SDL allocations to Rust- Descriptive bool-enums instead of bool parameters
- Builders wrapping the Properties API
- Encapsulation of reserved struct parameters
Footnotes
-
Certain SDL_gpu objects are an exception, since their destructors require an extra parameter. Such objects have a "manual"
drop()method, and have proper documentation of this fact. ↩