nostrdb-rs

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

commit 1a07d0c03c4cf604374f3cb15f87b36838a8fa6b
parent f9a8330a04f8fa41a8175ad8a61ceb0f79471da0
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 23 Jul 2024 12:41:47 -0700

temp ownership fix

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

Diffstat:
Msrc/ndb_str.rs | 6+++---
Msrc/note.rs | 4++--
Msrc/tags.rs | 34+++++++++++++++++-----------------
3 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/ndb_str.rs b/src/ndb_str.rs @@ -2,7 +2,7 @@ use crate::{bindings, Note}; pub struct NdbStr<'a> { ndb_str: bindings::ndb_str, - note: &'a Note<'a>, + note: Note<'a>, } #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -39,10 +39,10 @@ impl bindings::ndb_str { impl<'a> NdbStr<'a> { pub fn note(&self) -> &Note<'a> { - self.note + &self.note } - pub(crate) fn new(ndb_str: bindings::ndb_str, note: &'a Note<'a>) -> Self { + pub(crate) fn new(ndb_str: bindings::ndb_str, note: Note<'a>) -> Self { NdbStr { ndb_str, note } } diff --git a/src/note.rs b/src/note.rs @@ -192,9 +192,9 @@ impl<'a> Note<'a> { unsafe { bindings::ndb_note_kind(self.as_ptr()) } } - pub fn tags(&'a self) -> Tags<'a> { + pub fn tags(&self) -> Tags<'a> { let tags = unsafe { bindings::ndb_note_tags(self.as_ptr()) }; - Tags::new(tags, self) + Tags::new(tags, self.clone()) } pub fn sig(&self) -> &'a [u8; 64] { diff --git a/src/tags.rs b/src/tags.rs @@ -3,11 +3,11 @@ use crate::{bindings, NdbStr, Note}; #[derive(Debug, Clone)] pub struct Tag<'n> { ptr: *mut bindings::ndb_tag, - note: &'n Note<'n>, + note: Note<'n>, } impl<'n> Tag<'n> { - pub(crate) fn new(ptr: *mut bindings::ndb_tag, note: &'n Note<'n>) -> Self { + pub(crate) fn new(ptr: *mut bindings::ndb_tag, note: Note<'n>) -> Self { Tag { ptr, note } } @@ -23,7 +23,7 @@ impl<'n> Tag<'n> { ind as ::std::os::raw::c_int, ) }; - NdbStr::new(nstr, self.note) + NdbStr::new(nstr, self.note.clone()) } pub fn get(&self, ind: u16) -> Option<NdbStr<'n>> { @@ -33,8 +33,8 @@ impl<'n> Tag<'n> { Some(self.get_unchecked(ind)) } - pub fn note(&'n self) -> &'n Note<'n> { - self.note + pub fn note(&self) -> &Note<'n> { + &self.note } pub fn as_ptr(&self) -> *mut bindings::ndb_tag { @@ -54,7 +54,7 @@ impl<'a> IntoIterator for Tag<'a> { #[derive(Debug, Clone)] pub struct Tags<'a> { ptr: *mut bindings::ndb_tags, - note: &'a Note<'a>, + note: Note<'a>, } impl<'a> IntoIterator for Tags<'a> { @@ -62,12 +62,12 @@ impl<'a> IntoIterator for Tags<'a> { type IntoIter = TagsIter<'a>; fn into_iter(self) -> TagsIter<'a> { - TagsIter::new(self.note()) + TagsIter::new(self.note().clone()) } } impl<'a> Tags<'a> { - pub(crate) fn new(ptr: *mut bindings::ndb_tags, note: &'a Note<'a>) -> Self { + pub(crate) fn new(ptr: *mut bindings::ndb_tags, note: Note<'a>) -> Self { Tags { ptr, note } } @@ -76,11 +76,11 @@ impl<'a> Tags<'a> { } pub fn iter(&self) -> TagsIter<'a> { - TagsIter::new(self.note) + TagsIter::new(self.note.clone()) } - pub fn note(&self) -> &'a Note<'a> { - self.note + pub fn note(&self) -> &Note<'a> { + &self.note } pub fn as_ptr(&self) -> *mut bindings::ndb_tags { @@ -91,11 +91,11 @@ impl<'a> Tags<'a> { #[derive(Debug, Clone)] pub struct TagsIter<'a> { iter: bindings::ndb_iterator, - note: &'a Note<'a>, + note: Note<'a>, } impl<'a> TagsIter<'a> { - pub fn new(note: &'a Note<'a>) -> Self { + pub fn new(note: Note<'a>) -> Self { let iter = bindings::ndb_iterator { note: std::ptr::null_mut(), tag: std::ptr::null_mut(), @@ -103,7 +103,7 @@ impl<'a> TagsIter<'a> { }; let mut iter = TagsIter { note, iter }; unsafe { - bindings::ndb_tags_iterate_start(note.as_ptr(), &mut iter.iter); + bindings::ndb_tags_iterate_start(iter.note.as_ptr(), &mut iter.iter); }; iter } @@ -113,12 +113,12 @@ impl<'a> TagsIter<'a> { if tag_ptr.is_null() { None } else { - Some(Tag::new(tag_ptr, self.note())) + Some(Tag::new(tag_ptr, self.note().clone())) } } - pub fn note(&self) -> &'a Note<'a> { - self.note + pub fn note(&self) -> &Note<'a> { + &self.note } pub fn as_ptr(&self) -> *const bindings::ndb_iterator {