Skip to content

Commit

Permalink
clippy: fix warnings
Browse files Browse the repository at this point in the history
Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 committed Apr 27, 2024
1 parent 8092af6 commit 7e37116
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 26 deletions.
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
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
#[allow(unused)]
#[allow(clippy::upper_case_acronyms)]
mod bindings;

#[allow(unused)]
#[allow(non_snake_case)]
#[allow(clippy::needless_lifetimes)]
#[allow(clippy::missing_safety_doc)]
mod ndb_profile;

mod block;
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 @@ -324,7 +323,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
4 changes: 4 additions & 0 deletions src/ndb_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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: 2 additions & 3 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ impl<'a> Note<'a> {

impl<'a> Drop for Note<'a> {
fn drop(&mut self) {
match self {
Note::Owned { ptr, .. } => unsafe { libc::free((*ptr) as *mut libc::c_void) },
_ => (),
if let Note::Owned { ptr, .. } = self {
unsafe { libc::free((*ptr) as *mut libc::c_void) }
}
}
}
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
14 changes: 5 additions & 9 deletions src/util/nip10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,11 @@ fn tags_to_note_reply<'a>(tags: Tags<'a>) -> NoteReply<'a> {
}
}
}
} else {
if first {
root = Some(note_ref);
first = false;
} else {
if reply.is_none() {
reply = Some(note_ref)
}
}
} else if first {
root = Some(note_ref);
first = false;
} else if reply.is_none() {
reply = Some(note_ref)
}
}

Expand Down

0 comments on commit 7e37116

Please sign in to comment.