diff --git a/src/block.rs b/src/block.rs index 78b1bb3..932a785 100644 --- a/src/block.rs +++ b/src/block.rs @@ -170,7 +170,7 @@ impl<'a> Block<'a> { return ""; } - (&*str_block).as_str() + (*str_block).as_str() } } diff --git a/src/config.rs b/src/config.rs index 20deaed..10c6904 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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 { diff --git a/src/filter.rs b/src/filter.rs index 9d8c7e0..e5a0347 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -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(), @@ -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() } } @@ -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) { diff --git a/src/lib.rs b/src/lib.rs index 3894552..70622f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/ndb.rs b/src/ndb.rs index 19eb850..49714d3 100644 --- a/src/ndb.rs +++ b/src/ndb.rs @@ -1,4 +1,3 @@ -use libc; use std::ffi::CString; use std::ptr; @@ -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()) }; @@ -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> { @@ -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), } @@ -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 } } diff --git a/src/ndb_str.rs b/src/ndb_str.rs index b57c8e7..a2edf0e 100644 --- a/src/ndb_str.rs +++ b/src/ndb_str.rs @@ -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 diff --git a/src/note.rs b/src/note.rs index 7dce518..f4926ee 100644 --- a/src/note.rs +++ b/src/note.rs @@ -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) } } } } diff --git a/src/transaction.rs b/src/transaction.rs index 16c9909..13aabda 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -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 } } } diff --git a/src/util/nip10.rs b/src/util/nip10.rs index 8f27789..09ae7df 100644 --- a/src/util/nip10.rs +++ b/src/util/nip10.rs @@ -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) } }