libcamera/
version.rs

1//! Compile-time libcamera version information (from libcamera/version.h) and runtime version string.
2use std::ffi::CStr;
3
4use libcamera_sys::{
5    libcamera_version_string, LIBCAMERA_VERSION_MAJOR, LIBCAMERA_VERSION_MINOR, LIBCAMERA_VERSION_PATCH,
6};
7
8/// Compile-time libcamera version.
9#[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
22/// Version of libcamera headers linked at build time.
23pub const VERSION: Version = Version {
24    major: LIBCAMERA_VERSION_MAJOR,
25    minor: LIBCAMERA_VERSION_MINOR,
26    patch: LIBCAMERA_VERSION_PATCH,
27};
28
29impl Version {
30    /// Returns the compile-time version as a struct.
31    pub const fn current() -> Version {
32        VERSION
33    }
34}
35
36/// Runtime libcamera version string reported by `CameraManager::version()`.
37///
38/// This does not require creating or starting a `CameraManager`.
39pub fn runtime_version() -> &'static str {
40    unsafe { CStr::from_ptr(libcamera_version_string()) }.to_str().unwrap()
41}