Skip to content

Commit

Permalink
clipp: fix warnings
Browse files Browse the repository at this point in the history
Signed-off-by: William Casarin <jb55@jb55.com>
  • Loading branch information
jb55 committed Apr 12, 2024
1 parent 18e8d0d commit a30f597
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
mkShell {
nativeBuildInputs = [ rustPlatform.bindgenHook cargo rustc rustfmt libiconv pkg-config valgrind ];
nativeBuildInputs = [ rustPlatform.bindgenHook cargo clippy rustc rustfmt libiconv pkg-config valgrind ];

LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib";
}
1 change: 1 addition & 0 deletions src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::all)]
/* automatically generated by rust-bindgen 0.69.1 */

#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<'a> Block<'a> {
return "";
}

(&*str_block).as_str()
(*str_block).as_str()
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ pub struct Config {
pub config: bindings::ndb_config,
}

impl Default for Config {
fn default() -> Self {
Config::new()
}
}

impl Config {
pub fn new() -> Self {
let mut config = bindings::ndb_config {
Expand Down
15 changes: 11 additions & 4 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl Default for bindings::ndb_filter {
}

impl Filter {
#![allow(clippy::new_ret_no_self)]
pub fn new() -> FilterBuilder {
FilterBuilder {
data: Default::default(),
Expand All @@ -81,11 +82,17 @@ impl Filter {
}

pub fn as_ptr(&self) -> *const bindings::ndb_filter {
return self.data.as_ptr();
self.data.as_ptr()
}

pub fn as_mut_ptr(&mut self) -> *mut bindings::ndb_filter {
return self.data.as_mut_ptr() as *mut bindings::ndb_filter;
self.data.as_mut_ptr()
}
}

impl Default for FilterBuilder {
fn default() -> Self {
FilterBuilder::new()
}
}

Expand All @@ -97,11 +104,11 @@ impl FilterBuilder {
}

pub fn as_ptr(&self) -> *const bindings::ndb_filter {
return self.data.as_ptr();
self.data.as_ptr()
}

pub fn as_mut_ptr(&mut self) -> *mut bindings::ndb_filter {
return self.data.as_mut_ptr();
self.data.as_mut_ptr()
}

fn add_int_element(&mut self, i: u64) {
Expand Down
9 changes: 4 additions & 5 deletions src/ndb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use libc;
use std::ffi::CString;
use std::ptr;

Expand Down Expand Up @@ -49,7 +48,7 @@ impl Ndb {

let path = Path::new(db_dir);
if !path.exists() {
let _ = fs::create_dir_all(&path);
let _ = fs::create_dir_all(path);
}

let result = unsafe { bindings::ndb_init(&mut ndb, db_dir_cstr.as_ptr(), config.as_ptr()) };
Expand Down Expand Up @@ -144,7 +143,7 @@ impl Ndb {
vec.set_len(res as usize);
};

vec.into_iter().map(|n| NoteKey::new(n)).collect()
vec.into_iter().map(NoteKey::new).collect()
}

pub async fn wait_for_notes(&self, sub: &Subscription, max_notes: u32) -> Result<Vec<NoteKey>> {
Expand Down Expand Up @@ -172,7 +171,7 @@ impl Ndb {
});

match handle.await {
Ok(Ok(res)) => Ok(res.into_iter().map(|n| NoteKey::new(n)).collect()),
Ok(Ok(res)) => Ok(res.into_iter().map(NoteKey::new).collect()),
Ok(Err(err)) => Err(err),
Err(_) => Err(Error::SubscriptionError),
}
Expand Down Expand Up @@ -299,7 +298,7 @@ impl Ndb {

/// Get the underlying pointer to the context in C
pub fn as_ptr(&self) -> *mut bindings::ndb {
return self.refs.ndb;
self.refs.ndb
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/ndb_profile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// automatically generated by the FlatBuffers compiler, do not modify
#![allow(clippy::all)]

// automatically generated by the FlatBuffers compiler, do not modify

// @generated

Expand Down
4 changes: 4 additions & 0 deletions src/ndb_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ impl<'a> NdbStr<'a> {
NdbStr { ndb_str, note }
}

pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn len(&self) -> usize {
if self.ndb_str.flag == (bindings::NDB_PACKED_ID as u8) {
32
Expand Down
5 changes: 1 addition & 4 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ impl bindings::ndb_txn {
// just create something uninitialized. ndb_begin_query will initialize it for us
let lmdb: *mut bindings::ndb_lmdb = std::ptr::null_mut();
let mdb_txn: *mut ::std::os::raw::c_void = std::ptr::null_mut();
bindings::ndb_txn {
lmdb: lmdb,
mdb_txn: mdb_txn,
}
bindings::ndb_txn { lmdb, mdb_txn }
}
}

Expand Down

0 comments on commit a30f597

Please sign in to comment.