vips/
version.rs

1//! libvips version information encapsulation
2
3/// Returns the libvips version as a tuple: (major, minor, micro)
4///
5/// # Returns
6/// A tuple of three integers representing the major, minor, and micro version numbers.
7///
8/// # Example
9/// ```no_run
10/// use vips::version;
11///
12/// let (major, minor, micro) = version();
13/// println!("libvips version: {}.{}.{}", major, minor, micro);
14/// ```
15pub fn version() -> (i32, i32, i32) {
16    unsafe {
17        (
18            vips_sys::vips_version(0),
19            vips_sys::vips_version(1),
20            vips_sys::vips_version(2),
21        )
22    }
23}
24
25/// Returns the full version string, such as "8.14.2"
26///
27/// # Returns
28/// A string representing the full libvips version.
29///
30/// # Example
31/// ```no_run
32/// use vips::version_string;
33///
34/// let version_str = version_string();
35/// println!("libvips version string: {}", version_str);
36/// ```
37///
38/// # Note
39/// This function involves unsafe code to interface with the underlying C library.
40///
41/// # Safety
42/// The function assumes that the pointer returned by `vips_version_string` is valid
43/// and points to a null-terminated C string.
44///
45/// # Panics
46/// The function will panic if the C string is not valid UTF-8.
47///
48/// # Errors
49/// This function does not return errors; it will convert invalid UTF-8 to a lossy string.
50///
51/// # Performance
52/// The function may incur a small overhead due to the conversion from C string to Rust String.
53///
54/// # Thread Safety
55/// The function is safe to call from multiple threads as it does not modify any shared state.
56///
57pub fn version_string() -> String {
58    unsafe {
59        let c = std::ffi::CStr::from_ptr(vips_sys::vips_version_string());
60        c.to_string_lossy().into_owned()
61    }
62}