From 232ab1501c24ccfe343328253fb7317c6f58b87a Mon Sep 17 00:00:00 2001 From: Antoni Spaanderman <56turtle56@gmail.com> Date: Fri, 14 Jun 2024 22:25:59 +0200 Subject: [PATCH 1/2] Allow comparing Version by deriving PartialOrd and Ord, add constant with the version the bindings were compiled with --- src/sdl2/version.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/sdl2/version.rs b/src/sdl2/version.rs index 95ce2e2bf6e..8acbbec43ca 100644 --- a/src/sdl2/version.rs +++ b/src/sdl2/version.rs @@ -8,7 +8,7 @@ use std::fmt; use crate::sys; /// A structure that contains information about the version of SDL in use. -#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, PartialOrd, Ord)] pub struct Version { /// major version pub major: u8, @@ -19,6 +19,14 @@ pub struct Version { } impl Version { + /// The version of SDL that was used to generate the bindings. This may differ from the version + /// used at runtime, use [`version`] to get that. + pub const COMPILE_TIME_VERSION: Self = Self { + major: sys::SDL_MAJOR_VERSION as u8, + minor: sys::SDL_MINOR_VERSION as u8, + patch: sys::SDL_PATCHLEVEL as u8, + }; + /// Convert a raw *SDL_version to Version. pub fn from_ll(v: sys::SDL_version) -> Version { Version { From 2d6d87213f4de77ce06eb6bd9cc29755254f2c76 Mon Sep 17 00:00:00 2001 From: Antoni Spaanderman <56turtle56@gmail.com> Date: Fri, 14 Jun 2024 22:34:44 +0200 Subject: [PATCH 2/2] fix docs and add to changelog --- changelog.md | 2 ++ src/sdl2/version.rs | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index c19ab71cde3..76f74c4cfe9 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,8 @@ when upgrading from a version of rust-sdl2 to another. ### Next +[PR #1408](https://github.com/Rust-SDL2/rust-sdl2/pull/1408) Allow comparing `Version`s, add constant with the version the bindings were compiled with. + [PR #1407](https://github.com/Rust-SDL2/rust-sdl2/pull/1407) Add new use_ios_framework for linking to SDL2.framework on iOS ### v0.37.0 diff --git a/src/sdl2/version.rs b/src/sdl2/version.rs index 8acbbec43ca..427d7b18688 100644 --- a/src/sdl2/version.rs +++ b/src/sdl2/version.rs @@ -1,13 +1,11 @@ -/*! -Querying SDL Version - */ +//! Querying SDL Version use std::ffi::CStr; use std::fmt; use crate::sys; -/// A structure that contains information about the version of SDL in use. +/// A structure that contains a version of SDL. #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, PartialOrd, Ord)] pub struct Version { /// major version @@ -27,7 +25,7 @@ impl Version { patch: sys::SDL_PATCHLEVEL as u8, }; - /// Convert a raw *SDL_version to Version. + /// Convert a raw SDL_version to Version. pub fn from_ll(v: sys::SDL_version) -> Version { Version { major: v.major,