sdl3_sys/generated/
guid.rs

1//! A GUID is a 128-bit value that represents something that is uniquely
2//! identifiable by this value: "globally unique."
3//!
4//! SDL provides functions to convert a GUID to/from a string.
5
6use super::stdinc::*;
7
8/// An [`SDL_GUID`] is a 128-bit identifier for an input device that identifies
9/// that device across runs of SDL programs on the same platform.
10///
11/// If the device is detached and then re-attached to a different port, or if
12/// the base system is rebooted, the device should still report the same GUID.
13///
14/// GUIDs are as precise as possible but are not guaranteed to distinguish
15/// physically distinct but equivalent devices. For example, two game
16/// controllers from the same vendor with the same product ID and revision may
17/// have the same GUID.
18///
19/// GUIDs may be platform-dependent (i.e., the same device may report different
20/// GUIDs on different operating systems).
21///
22/// ## Availability
23/// This struct is available since SDL 3.2.0.
24#[repr(C)]
25#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
26pub struct SDL_GUID {
27    pub data: [Uint8; 16],
28}
29
30#[cfg(feature = "debug-impls")]
31impl ::core::fmt::Debug for SDL_GUID {
32    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
33        write!(f, "SDL_GUID({self})")
34    }
35}
36
37#[cfg(any(feature = "display-impls", feature = "debug-impls"))]
38impl ::core::fmt::Display for SDL_GUID {
39    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
40        for byte in self.data {
41            write!(f, "{byte:02x}")?;
42        }
43        Ok(())
44    }
45}
46
47unsafe extern "C" {
48    /// Get an ASCII string representation for a given [`SDL_GUID`].
49    ///
50    /// ## Parameters
51    /// - `guid`: the [`SDL_GUID`] you wish to convert to string.
52    /// - `pszGUID`: buffer in which to write the ASCII string.
53    /// - `cbGUID`: the size of pszGUID, should be at least 33 bytes.
54    ///
55    /// ## Thread safety
56    /// It is safe to call this function from any thread.
57    ///
58    /// ## Availability
59    /// This function is available since SDL 3.2.0.
60    ///
61    /// ## See also
62    /// - [`SDL_StringToGUID`]
63    pub fn SDL_GUIDToString(
64        guid: SDL_GUID,
65        pszGUID: *mut ::core::ffi::c_char,
66        cbGUID: ::core::ffi::c_int,
67    );
68}
69
70unsafe extern "C" {
71    /// Convert a GUID string into a [`SDL_GUID`] structure.
72    ///
73    /// Performs no error checking. If this function is given a string containing
74    /// an invalid GUID, the function will silently succeed, but the GUID generated
75    /// will not be useful.
76    ///
77    /// ## Parameters
78    /// - `pchGUID`: string containing an ASCII representation of a GUID.
79    ///
80    /// ## Return value
81    /// Returns a [`SDL_GUID`] structure.
82    ///
83    /// ## Thread safety
84    /// It is safe to call this function from any thread.
85    ///
86    /// ## Availability
87    /// This function is available since SDL 3.2.0.
88    ///
89    /// ## See also
90    /// - [`SDL_GUIDToString`]
91    pub fn SDL_StringToGUID(pchGUID: *const ::core::ffi::c_char) -> SDL_GUID;
92}
93
94#[cfg(doc)]
95use crate::everything::*;