1use std::ffi::CStr;
3
4use libcamera_sys::{
5 libcamera_version_string, LIBCAMERA_VERSION_MAJOR, LIBCAMERA_VERSION_MINOR, LIBCAMERA_VERSION_PATCH,
6};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub struct Version {
11 pub major: u32,
12 pub minor: u32,
13 pub patch: u32,
14}
15
16impl core::fmt::Display for Version {
17 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
18 write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
19 }
20}
21
22pub const VERSION: Version = Version {
24 major: LIBCAMERA_VERSION_MAJOR,
25 minor: LIBCAMERA_VERSION_MINOR,
26 patch: LIBCAMERA_VERSION_PATCH,
27};
28
29impl Version {
30 pub const fn current() -> Version {
32 VERSION
33 }
34}
35
36pub fn runtime_version() -> &'static str {
40 unsafe { CStr::from_ptr(libcamera_version_string()) }.to_str().unwrap()
41}