nostrdb-rs

nostrdb in rust!
git clone git://jb55.com/nostrdb-rs
Log | Files | Refs | Submodules | README | LICENSE

commit 7e371166e602820e7c3bee75d178f63b6e6631b7
parent 8092af6cd4532e622a042e3891fc0cc82d341638
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 26 Apr 2024 18:11:14 -0700

clippy: fix warnings

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/block.rs | 2+-
Msrc/config.rs | 6++++++
Msrc/filter.rs | 15+++++++++++----
Msrc/lib.rs | 3+++
Msrc/ndb.rs | 9++++-----
Msrc/ndb_str.rs | 4++++
Msrc/note.rs | 5++---
Msrc/transaction.rs | 5+----
Msrc/util/nip10.rs | 14+++++---------
9 files changed, 37 insertions(+), 26 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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<Vec<NoteKey>> { @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) } }