linera-protocol icon indicating copy to clipboard operation
linera-protocol copied to clipboard

[nits] Introduce `into_saved(self)` for `RootView`.

Open MathieuDutSik opened this issue 5 months ago • 2 comments

So, now we have the pattern in fn save.

let mut batch = Batch::new();
view.pre_save(&mut batch)?;
store.write_batch(batch).await?;
view.post_save();

In the functions fn finalize of the smart contracts we often have the pattern

    async fn store(mut self) {
        self.state.save().await.expect("Failed to save state");
    }

This means that the post_save is done for no reason (but maybe elided away by the compiler). It would make sense to have into_saved that does the pre_save, write_batch, but not the post_save.

MathieuDutSik avatar Nov 17 '25 07:11 MathieuDutSik

(Or fn save_and_drop(self)?) Because it wouldn't return a Self anymore, would it? It would just consume it?

afck avatar Nov 17 '25 09:11 afck

Yes, it would consume it. So yes save_and_drop makes sense.

MathieuDutSik avatar Nov 17 '25 09:11 MathieuDutSik