Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow comparing Version by deriving PartialOrd and Ord, add constant with the version the bindings were compiled with #1408

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions src/sdl2/version.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/*!
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.
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
/// A structure that contains a version of SDL.
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, PartialOrd, Ord)]
pub struct Version {
/// major version
pub major: u8,
Expand All @@ -19,7 +17,15 @@ pub struct Version {
}

impl Version {
/// Convert a raw *SDL_version to 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 {
major: v.major,
Expand Down
Loading