Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions rust/cuvs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ pub mod vamana;
pub use dlpack::{AsDlTensor, AsDlTensorMut, DLPackError, DLTensorView, DLTensorViewMut, DType};
pub use error::{Error, Result};
pub use resources::Resources;

/// Returns the version of this `cuvs` crate.
pub fn version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
Comment on lines +31 to +33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest instead to wrap the underlying FFI function like so.

/// Returns the cuVS library version as `(major, minor, patch)`.
pub fn version() -> Result<(u16, u16, u16), LibraryError> {
    let mut major: u16 = 0;
    let mut minor: u16 = 0;
    let mut patch: u16 = 0;

    // SAFETY:
    // - All three pointers are valid, aligned `u16` locals.
    let status = unsafe { ffi::cuvsVersionGet(&mut major, &mut minor, &mut patch) };
    check_cuvs(status)?;
    Ok((major, minor, patch))
}


#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_version() {
assert_eq!(version(), env!("CARGO_PKG_VERSION"));
}
}
Loading