Skip to content

Commit b2c8913

Browse files
authored
Merge pull request #60 from molpopgen/tskit_C_version
Add functions to return C API version info
2 parents 87593d4 + f48b2fe commit b2c8913

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/lib.rs

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

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

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

0 commit comments

Comments
 (0)