rich_sdl2_rust/
lib.rs

1#![allow(unused)]
2#![warn(missing_docs)]
3#![warn(rustdoc::broken_intra_doc_links)]
4#![cfg_attr(feature = "simd_allocator", feature(allocator_api))]
5#![cfg_attr(feature = "nightly", feature(doc_cfg))]
6
7//! # rich-sdl2-rust
8//!
9//! The rich-sdl2-rust provides wrapper for SDL2 and abstractions of that APIs, [`audio`], [`window`], [`EventBox`] and so on.
10//!
11//! ## Supported SDL versions
12//!
13//! This crate works with libraries:
14//!
15//! - SDL 2.26.2 or later,
16//! - SDL_ttf 2.20.1 or later (on `ttf` feature),
17//! - SDL_mixer 2.6.2 or later (on `mixer` feature),
18//! - SDL_image 2.6.2 or later (on `image` feature),
19//! - SDL_net 2.2.0 or later (on `net` feature).
20//!
21//! ## Module Navigation
22//!
23//! - [Window and Graphics](window)
24//! - [Simple Audio Control](audio)
25//! - [Handling Events](EventBox)
26//! - ...
27//!
28//! ## Crate features
29//!
30//! - `vulkan`: The Vulkan support API wrapper.
31//! - `nightly`: The features can be used on nightly.
32//!   - `simd_allocator`: The wrapper of SIMD-friendly allocator.
33
34pub mod audio;
35mod error;
36pub mod event;
37pub mod file;
38pub mod haptic;
39pub mod hint;
40#[cfg(feature = "image")]
41pub mod image;
42#[cfg(feature = "mixer")]
43pub mod mixer;
44#[cfg(feature = "net")]
45pub mod net;
46pub mod power;
47mod sdl;
48pub mod system;
49mod timer;
50#[cfg(feature = "ttf")]
51pub mod ttf;
52mod video;
53
54use rich_sdl2_rust_sys as bind;
55
56pub use error::*;
57pub use event::{app, EventBox};
58pub use sdl::*;
59pub use timer::*;
60pub use video::*;
61
62#[cfg(not(target_env = "msvc"))]
63type EnumInt = std::os::raw::c_uint;
64#[cfg(target_env = "msvc")]
65type EnumInt = std::os::raw::c_int;
66
67/// Converts an option reference into a constant raw pointer.
68///
69/// # Safety
70///
71/// The object of `opt` must live over usage of a returned pointer. Otherwise it will occur UB.
72pub(crate) unsafe fn as_raw<T>(opt: &Option<T>) -> *const T {
73    opt.as_ref().map_or(std::ptr::null(), |x| x)
74}
75
76/// Converts an option reference into a mutable raw pointer.
77///
78/// # Safety
79///
80/// The object of `opt` must live over usage of a returned pointer. Otherwise it will occur UB.
81pub(crate) unsafe fn as_raw_mut<T>(opt: &mut Option<T>) -> *mut T {
82    opt.as_mut().map_or(std::ptr::null_mut(), |x| &mut *x)
83}