From 892a395c86caf999fecce60ef747550644929161 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sat, 16 Dec 2023 17:26:17 -0800 Subject: [PATCH] note: add method for getting note content --- src/note.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/note.rs b/src/note.rs index 2f721b7..713d343 100644 --- a/src/note.rs +++ b/src/note.rs @@ -67,6 +67,19 @@ impl<'a> Note<'a> { } } + fn content_size(&self) -> usize { + unsafe { bindings::ndb_note_content_length(self.as_ptr()) as usize } + } + + /// Get the [`Note`] contents. + pub fn content(&self) -> &'a str { + unsafe { + let content = bindings::ndb_note_content(self.as_ptr()); + let byte_slice = std::slice::from_raw_parts(content as *const u8, self.content_size()); + std::str::from_utf8_unchecked(byte_slice) + } + } + pub fn kind(&self) -> u32 { unsafe { bindings::ndb_note_kind(self.as_ptr()) } }