-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add wrappers for the
hb_version*
functions. (#236)
This will be useful moving forward as we start to update the library version.
- Loading branch information
1 parent
d191c28
commit dcd3903
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 The Servo Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use crate::sys::{hb_version, hb_version_atleast, hb_version_string}; | ||
|
||
/// Returns the HarfBuzz library version. | ||
/// | ||
/// # Example: | ||
/// | ||
/// ``` | ||
/// let (major, minor, patch) = harfbuzz::version(); | ||
/// println!("HarfBuzz version {}.{}.{}", major, minor, patch); | ||
/// ``` | ||
pub fn version() -> (u32, u32, u32) { | ||
let mut major: u32 = 0; | ||
let mut minor: u32 = 0; | ||
let mut patch: u32 = 0; | ||
unsafe { | ||
hb_version(&mut major, &mut minor, &mut patch); | ||
} | ||
(major, minor, patch) | ||
} | ||
|
||
/// Returns true if the HarfBuzz library version is at least the given version. | ||
/// | ||
/// # Example: | ||
/// | ||
/// ``` | ||
/// assert!(harfbuzz::version_atleast(2, 0, 0)); | ||
/// ``` | ||
pub fn version_atleast(major: u32, minor: u32, patch: u32) -> bool { | ||
unsafe { hb_version_atleast(major, minor, patch) != 0 } | ||
} | ||
|
||
/// Returns the HarfBuzz library version as a string. | ||
/// | ||
/// # Example: | ||
/// | ||
/// ``` | ||
/// println!("HarfBuzz version {}", harfbuzz::version_string()); | ||
/// ``` | ||
pub fn version_string() -> &'static str { | ||
unsafe { core::ffi::CStr::from_ptr(hb_version_string()) } | ||
.to_str() | ||
.unwrap() | ||
} |