From ceadd8928ec8dd0400f708377cfa65f78578d146 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 24 Feb 2024 19:49:36 +0000 Subject: [PATCH] api: add ContextBuilder.build() to build Context without opening --- src/context.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/context.rs b/src/context.rs index d903430d65..08e18c6583 100644 --- a/src/context.rs +++ b/src/context.rs @@ -153,11 +153,19 @@ impl ContextBuilder { self } - /// Opens the [`Context`]. - pub async fn open(self) -> Result { + /// Builds the [`Context`] without opening it. + pub async fn build(self) -> Result { let context = Context::new_closed(&self.dbfile, self.id, self.events, self.stock_strings).await?; - let password = self.password.unwrap_or_default(); + Ok(context) + } + + /// Builds the [`Context`] and opens it. + /// + /// Returns error if context cannot be opened with the given passphrase. + pub async fn open(self) -> Result { + let password = self.password.clone().unwrap_or_default(); + let context = self.build().await?; match context.open(password).await? { true => Ok(context), false => bail!("database could not be decrypted, incorrect or missing password"),