Skip to content

Commit dcd3903

Browse files
Add wrappers for the hb_version* functions. (#236)
This will be useful moving forward as we start to update the library version.
1 parent d191c28 commit dcd3903

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

harfbuzz/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ pub use self::language::Language;
3939

4040
mod blob;
4141
pub use self::blob::Blob;
42+
43+
mod version;
44+
pub use self::version::{version, version_atleast, version_string};

harfbuzz/src/version.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
10+
use 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+
/// ```
20+
pub 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+
/// ```
37+
pub 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+
/// ```
48+
pub fn version_string() -> &'static str {
49+
unsafe { core::ffi::CStr::from_ptr(hb_version_string()) }
50+
.to_str()
51+
.unwrap()
52+
}

0 commit comments

Comments
 (0)