From 51f9d6f0440c74985c695b64bc790cd4dae03bb4 Mon Sep 17 00:00:00 2001 From: Evan Mesterhazy Date: Fri, 1 Mar 2024 12:21:41 -0500 Subject: [PATCH] Remove the std::Option around UnpublishedOperation::data The Option is unnecessary now since `UnpublishedOperation` doesn't implement the Drop trait (the `MustClose` member implements it instead). --- lib/src/transaction.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index 062d0a0c0d..92855c367e 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -162,7 +162,7 @@ struct NewRepoData { #[must_use = "Either publish() or leave_unpublished() must be called to finish the operation."] pub struct UnpublishedOperation { repo_loader: RepoLoader, - data: Option, + data: NewRepoData, } impl UnpublishedOperation { @@ -172,20 +172,22 @@ impl UnpublishedOperation { view: View, index: Box, ) -> Self { - let data = Some(NewRepoData { - operation, - view, - index, - }); - UnpublishedOperation { repo_loader, data } + UnpublishedOperation { + repo_loader, + data: NewRepoData { + operation, + view, + index, + }, + } } pub fn operation(&self) -> &Operation { - &self.data.as_ref().unwrap().operation + &self.data.operation } - pub fn publish(mut self) -> Arc { - let data = self.data.take().unwrap(); + pub fn publish(self) -> Arc { + let data = self.data; { let _lock = self.repo_loader.op_heads_store().lock(); self.repo_loader @@ -196,9 +198,8 @@ impl UnpublishedOperation { .create_from(data.operation, data.view, data.index) } - pub fn leave_unpublished(mut self) -> Arc { - let data = self.data.take().unwrap(); + pub fn leave_unpublished(self) -> Arc { self.repo_loader - .create_from(data.operation, data.view, data.index) + .create_from(self.data.operation, self.data.view, self.data.index) } }