Skip to main content

rocketmq_store_api/capability/
lifecycle.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::future::Future;
16
17use crate::StoreError;
18
19/// Storage lifecycle capability.
20pub trait StoreLifecycle: Send + Sync {
21    /// Loads existing state.
22    ///
23    /// # Errors
24    ///
25    /// Returns [`StoreError`] with [`crate::StoreOperation::Load`] when state
26    /// cannot be loaded safely.
27    fn load(&mut self) -> impl Future<Output = Result<bool, StoreError>> + Send;
28
29    /// Starts the store within its existing lifecycle owner.
30    ///
31    /// # Errors
32    ///
33    /// Returns [`StoreError`] with [`crate::StoreOperation::Start`] when
34    /// startup cannot establish a usable store.
35    fn start(&mut self) -> impl Future<Output = Result<(), StoreError>> + Send;
36
37    /// Stops the store and completes its owned shutdown sequence.
38    ///
39    /// # Errors
40    ///
41    /// Returns [`StoreError`] with [`crate::StoreOperation::Shutdown`] when
42    /// final progress or shutdown fails.
43    fn shutdown(&mut self) -> impl Future<Output = Result<(), StoreError>> + Send;
44}