Skip to content

Commit f48b2fe

Browse files
committed
Add functions to return C API version info
1 parent 6b9631e commit f48b2fe

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/lib.rs

+41-1
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,50 @@ pub use trees::{NodeIterator, NodeTraversalOrder, Tree, TreeFlags, TreeSequence}
5252
/// the error message is stored for diplay.
5353
pub type TskReturnValue = Result<i32, TskitError>;
5454

55-
/// Get the tskit version number.
55+
/// Version of the rust crate.
56+
///
57+
/// To get the C API version, see:
58+
/// * [`c_api_major_version`]
59+
/// * [`c_api_minor_version`]
60+
/// * [`c_api_patch_version`]
5661
pub fn version() -> &'static str {
5762
return env!("CARGO_PKG_VERSION");
5863
}
5964

65+
/// C API major version
66+
pub fn c_api_major_version() -> u32 {
67+
bindings::TSK_VERSION_MAJOR
68+
}
69+
70+
/// C API minor version
71+
pub fn c_api_minor_version() -> u32 {
72+
bindings::TSK_VERSION_MINOR
73+
}
74+
75+
/// C API patch version
76+
pub fn c_api_patch_version() -> u32 {
77+
bindings::TSK_VERSION_PATCH
78+
}
79+
80+
/// The C API version in MAJOR.MINOR.PATCH format
81+
pub fn c_api_version() -> String {
82+
String::from(format!(
83+
"{}.{}.{}",
84+
c_api_major_version(),
85+
c_api_minor_version(),
86+
c_api_patch_version()
87+
))
88+
}
89+
90+
#[cfg(test)]
91+
mod tests {
92+
use super::c_api_version;
93+
94+
#[test]
95+
fn test_c_api_version() {
96+
let _ = c_api_version();
97+
}
98+
}
99+
60100
// Testing modules
61101
mod test_tsk_variables;

0 commit comments

Comments
 (0)