From 5ed0398203569d0f549c50df724bfd566d108067 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 15 Aug 2023 11:03:15 +0300 Subject: [PATCH] db(+async) writer: add push_by_ref --- lib/src/async_db.rs | 4 ++++ lib/src/db.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/src/async_db.rs b/lib/src/async_db.rs index 991e825..5b6e8be 100644 --- a/lib/src/async_db.rs +++ b/lib/src/async_db.rs @@ -84,6 +84,10 @@ where } pub async fn push(&mut self, item: T) -> Result<(), String> { + self.push_by_ref(&item).await + } + + pub async fn push_by_ref(&mut self, item: &T) -> Result<(), String> { let pos: LSize = self.data_buf.len() as LSize; bincode::encode_into_writer(item, &mut self.cur_buf_item, BINCODE_CFG).str_err()?; diff --git a/lib/src/db.rs b/lib/src/db.rs index 003a2b0..17d94f9 100644 --- a/lib/src/db.rs +++ b/lib/src/db.rs @@ -77,6 +77,10 @@ where } pub fn push(&mut self, item: T) -> Result<(), String> { + self.push_by_ref(&item) + } + + pub fn push_by_ref(&mut self, item: &T) -> Result<(), String> { let pos: LSize = self.data_buf.position() as LSize; bincode::encode_into_writer(item, &mut self.cur_buf_item, BINCODE_CFG).str_err()?;