Skip to content

Commit

Permalink
Add explicit convertions for bool type
Browse files Browse the repository at this point in the history
  • Loading branch information
ava57r committed Jun 10, 2021
1 parent 33d8a82 commit 9834edb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
12 changes: 0 additions & 12 deletions faiss-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
6 changes: 3 additions & 3 deletions src/index/id_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -264,13 +265,12 @@ impl<I> Index for IdMap<I> {
}

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));
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down

0 comments on commit 9834edb

Please sign in to comment.