harfbuzz/
version.rs

1// Copyright 2023 The Servo Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10use crate::sys::{hb_version, hb_version_atleast, hb_version_string};
11
12/// Returns the HarfBuzz library version.
13///
14/// # Example:
15///
16/// ```
17/// let (major, minor, patch) = harfbuzz::version();
18/// println!("HarfBuzz version {}.{}.{}", major, minor, patch);
19/// ```
20pub fn version() -> (u32, u32, u32) {
21    let mut major: u32 = 0;
22    let mut minor: u32 = 0;
23    let mut patch: u32 = 0;
24    unsafe {
25        hb_version(&mut major, &mut minor, &mut patch);
26    }
27    (major, minor, patch)
28}
29
30/// Returns true if the HarfBuzz library version is at least the given version.
31///
32/// # Example:
33///
34/// ```
35/// assert!(harfbuzz::version_atleast(2, 0, 0));
36/// ```
37pub fn version_atleast(major: u32, minor: u32, patch: u32) -> bool {
38    unsafe { hb_version_atleast(major, minor, patch) != 0 }
39}
40
41/// Returns the HarfBuzz library version as a string.
42///
43/// # Example:
44///
45/// ```
46/// println!("HarfBuzz version {}", harfbuzz::version_string());
47/// ```
48pub fn version_string() -> &'static str {
49    unsafe { core::ffi::CStr::from_ptr(hb_version_string()) }
50        .to_str()
51        .unwrap()
52}