commit 892a395c86caf999fecce60ef747550644929161 parent cb1c7683dd9871b3a717f704a4a2fb701bb42431 Author: William Casarin <jb55@jb55.com> Date: Sat, 16 Dec 2023 17:26:17 -0800 note: add method for getting note content Diffstat:
M | src/note.rs | | | 13 | +++++++++++++ |
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git 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()) } }