libmpv_client/
version.rs

1//! Various functions for ensuring that the currently used mpv player and header match the version this crate was intended for.
2
3use crate::*;
4use crate::error::{RustError, VersionError};
5
6/// Checks that the mpv/client.h passed to bindgen matches the version of mpv that this crate was written for.
7pub fn generated_version_check() -> Result<()> {
8    if libmpv_client_sys::MPV_CLIENT_API_VERSION == libmpv_client_sys::EXPECTED_MPV_VERSION {
9        Ok(())
10    } else {
11        Err(Error::Rust(RustError::VersionMismatch(VersionError {
12            expected: libmpv_client_sys::EXPECTED_MPV_VERSION as u64,
13            found: libmpv_client_sys::MPV_CLIENT_API_VERSION as u64,
14        })))
15    }
16}
17
18/// Checks that the [`MPV_CLIENT_API_VERSION`](libmpv_client_sys::MPV_CLIENT_API_VERSION) of the client matches the version of mpv this crate was built for.
19pub fn version_check() -> Result<()> {
20    let version = Handle::client_api_version();
21    if version == libmpv_client_sys::EXPECTED_MPV_VERSION as u64 {
22        Ok(())
23    } else {
24        Err(Error::Rust(RustError::VersionMismatch(VersionError {
25            expected: libmpv_client_sys::EXPECTED_MPV_VERSION as u64,
26            found: version,
27        })))
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn generated_version_check_test() -> Result<()> {
37        generated_version_check()
38    }
39}