diff --git a/faiss-sys/src/lib.rs b/faiss-sys/src/lib.rs index fc8eaf4..c0505fd 100644 --- a/faiss-sys/src/lib.rs +++ b/faiss-sys/src/lib.rs @@ -12,18 +12,6 @@ mod bindings; #[cfg(not(feature = "gpu"))] pub use bindings::*; -pub fn bool_as_c_int(v: bool) -> ::std::os::raw::c_int { - if v { - 1 - } else { - 0 - } -} - -pub fn c_int_as_bool(v: ::std::os::raw::c_int) -> bool { - v != 0 -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/index/id_map.rs b/src/index/id_map.rs index 93d924b..c836d2f 100644 --- a/src/index/id_map.rs +++ b/src/index/id_map.rs @@ -64,6 +64,7 @@ use faiss_sys::*; use std::marker::PhantomData; use std::mem; +use std::os::raw::c_int; use std::ptr; /// Wrapper for implementing arbitrary ID mapping to an index. @@ -264,13 +265,12 @@ impl Index for IdMap { } fn verbose(&self) -> bool { - unsafe { c_int_as_bool(faiss_Index_verbose(self.inner_ptr())) } + unsafe { faiss_Index_verbose(self.inner_ptr()) != 0 } } fn set_verbose(&mut self, value: bool) { unsafe { - let val_ = bool_as_c_int(value); - faiss_Index_set_verbose(self.inner_ptr(), val_); + faiss_Index_set_verbose(self.inner_ptr(), c_int::from(value)); } } } diff --git a/src/macros.rs b/src/macros.rs index 404810b..6451dfc 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -124,13 +124,12 @@ macro_rules! impl_native_index { } fn verbose(&self) -> bool { - unsafe { c_int_as_bool(faiss_Index_verbose(self.inner_ptr())) } + unsafe { faiss_Index_verbose(self.inner_ptr()) != 0 } } fn set_verbose(&mut self, value: bool) { unsafe { - let val_ = bool_as_c_int(value); - faiss_Index_set_verbose(self.inner_ptr(), val_); + faiss_Index_set_verbose(self.inner_ptr(), std::os::raw::c_int::from(value)); } } }