nostrdb-rs

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

commit d24238608c77dea0fb63356dc7188d58e0074192
parent 63e89223cdd1ecd6a7341815dcdbae466d2e74cd
Author: William Casarin <jb55@jb55.com>
Date:   Wed,  9 Apr 2025 12:58:28 -0700

note: inline note functions

rust probably inlines these already, but let's be
explicit

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

Diffstat:
Msrc/note.rs | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/note.rs b/src/note.rs @@ -141,6 +141,7 @@ impl<'a> Note<'a> { } } + #[inline] pub fn txn(&'a self) -> Option<&'a Transaction> { match self { Note::Transactional { transaction, .. } => Some(transaction), @@ -150,6 +151,7 @@ impl<'a> Note<'a> { /// Returns a database cursor that iterates over all of the relays /// that the note has been seen on + #[inline] pub fn relays(&self, txn: &'a Transaction) -> NoteRelays<'a> { let Some(note_key) = self.key() else { return NoteRelays::empty(); @@ -158,6 +160,7 @@ impl<'a> Note<'a> { NoteRelays::new(txn, note_key) } + #[inline] pub fn key(&self) -> Option<NoteKey> { match self { Note::Transactional { key, .. } => Some(NoteKey::new(key.as_u64())), @@ -165,6 +168,7 @@ impl<'a> Note<'a> { } } + #[inline] pub fn size(&self) -> usize { match self { Note::Owned { size, .. } => *size, @@ -172,6 +176,7 @@ impl<'a> Note<'a> { } } + #[inline] pub fn as_ptr(&self) -> *mut bindings::ndb_note { match self { Note::Owned { ptr, .. } => *ptr, @@ -179,6 +184,7 @@ impl<'a> Note<'a> { } } + #[inline] pub fn json_with_bufsize(&self, bufsize: usize) -> Result<String, Error> { let mut buf = Vec::with_capacity(bufsize); unsafe { @@ -199,24 +205,29 @@ impl<'a> Note<'a> { } } + #[inline] pub fn json(&self) -> Result<String, Error> { // 1mb buffer self.json_with_bufsize(1024usize * 1024usize) } + #[inline] fn content_size(&self) -> usize { unsafe { bindings::ndb_note_content_length(self.as_ptr()) as usize } } + #[inline] pub fn created_at(&self) -> u64 { unsafe { bindings::ndb_note_created_at(self.as_ptr()).into() } } + #[inline] pub fn content_ptr(&self) -> *const ::std::os::raw::c_char { unsafe { bindings::ndb_note_content(self.as_ptr()) } } /// Get the [`Note`] contents. + #[inline] pub fn content(&self) -> &'a str { unsafe { let content = self.content_ptr(); @@ -226,6 +237,7 @@ impl<'a> Note<'a> { } /// Get the note pubkey + #[inline] pub fn pubkey(&self) -> &'a [u8; 32] { unsafe { let ptr = bindings::ndb_note_pubkey(self.as_ptr()); @@ -233,6 +245,7 @@ impl<'a> Note<'a> { } } + #[inline] pub fn id(&self) -> &'a [u8; 32] { unsafe { let ptr = bindings::ndb_note_id(self.as_ptr()); @@ -240,15 +253,18 @@ impl<'a> Note<'a> { } } + #[inline] pub fn kind(&self) -> u32 { unsafe { bindings::ndb_note_kind(self.as_ptr()) } } + #[inline] pub fn tags(&self) -> Tags<'a> { let tags = unsafe { bindings::ndb_note_tags(self.as_ptr()) }; Tags::new(tags, self.clone()) } + #[inline] pub fn sig(&self) -> &'a [u8; 64] { unsafe { let ptr = bindings::ndb_note_sig(self.as_ptr());