commit ce2f5dbc3e289c65860982505b28adff053b49d3
parent df03575b0a0133d8700e90d538c01d253f4a480a
Author: William Casarin <jb55@jb55.com>
Date: Mon, 20 Jan 2025 13:54:48 -0800
tags: add porcelain api for getting ids and strings
It was a bit verbose before
Suggested-by: kieran
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/src/ndb_str.rs b/src/ndb_str.rs
@@ -58,6 +58,14 @@ impl<'a> NdbStr<'a> {
}
}
+ pub fn id(&self) -> Option<&'a [u8; 32]> {
+ self.variant().id()
+ }
+
+ pub fn str(&self) -> Option<&'a str> {
+ self.variant().str()
+ }
+
pub fn variant(&self) -> NdbStrVariant<'a> {
if self.ndb_str.flag == (bindings::NDB_PACKED_ID as u8) {
unsafe { NdbStrVariant::Id(&*(self.ndb_str.id() as *const [u8; 32])) }
diff --git a/src/tags.rs b/src/tags.rs
@@ -26,6 +26,14 @@ impl<'n> Tag<'n> {
NdbStr::new(nstr, self.note.clone())
}
+ pub fn get_str(&self, ind: u16) -> Option<&'n str> {
+ self.get(ind).and_then(|s| s.str())
+ }
+
+ pub fn get_id(&self, ind: u16) -> Option<&'n [u8; 32]> {
+ self.get(ind).and_then(|s| s.id())
+ }
+
pub fn get(&self, ind: u16) -> Option<NdbStr<'n>> {
if ind >= self.count() {
return None;