From d78e00bfbed93054b3f25a407737585eb56ece83 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 23 Apr 2024 17:52:25 -0700 Subject: [PATCH] extract transactional profile record so we can act on it directly Signed-off-by: William Casarin --- src/profile.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/profile.rs b/src/profile.rs index fe89e8b..cfe6c56 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -3,29 +3,28 @@ use crate::ndb_profile::{ }; use crate::{Error, Result, Transaction}; -pub enum ProfileRecord<'a> { - Transactional { - record: NdbProfileRecord<'a>, - primary_key: u64, - transaction: &'a Transaction, - }, +pub struct TransactionalProfileRecord<'a> { + pub record: NdbProfileRecord<'a>, + pub primary_key: u64, + pub transaction: &'a Transaction, +} - Owned { - record: NdbProfileRecord<'a>, - }, +pub enum ProfileRecord<'a> { + Transactional(TransactionalProfileRecord<'a>), + Owned(NdbProfileRecord<'a>), } impl<'a> ProfileRecord<'a> { pub fn record(&self) -> NdbProfileRecord<'a> { match self { - ProfileRecord::Transactional { record, .. } => *record, - ProfileRecord::Owned { record } => *record, + ProfileRecord::Transactional(tr) => tr.record, + ProfileRecord::Owned(r) => *r, } } pub fn new_owned(root: &'a [u8]) -> Result> { let record = root_as_ndb_profile_record(root).map_err(|_| Error::DecodeError)?; - Ok(ProfileRecord::Owned { record }) + Ok(ProfileRecord::Owned(record)) } pub(crate) fn new_transactional( @@ -38,11 +37,11 @@ impl<'a> ProfileRecord<'a> { let bytes = std::slice::from_raw_parts(ptr as *const u8, len); root_as_ndb_profile_record_unchecked(bytes) }; - ProfileRecord::Transactional { + ProfileRecord::Transactional(TransactionalProfileRecord { record, transaction, primary_key, - } + }) } }