engula_journal/
journal.rs

1// Copyright 2021 The Engula 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 crate::{async_trait, Result, Stream};
16
17/// An interface to manipulate a journal.
18#[async_trait]
19pub trait Journal: Clone + Send + Sync + 'static {
20    type Stream: Stream;
21
22    /// Returns a stream.
23    async fn stream(&self, name: &str) -> Result<Self::Stream>;
24
25    /// Creates a stream.
26    ///
27    /// # Errors
28    ///
29    /// Returns `Error::AlreadyExists` if the stream already exists.
30    async fn create_stream(&self, name: &str) -> Result<Self::Stream>;
31
32    /// Deletes a stream.
33    ///
34    /// Using a deleted stream is an undefined behavior.
35    ///
36    /// # Errors
37    ///
38    /// Returns `Error::NotFound` if the stream doesn't exist.
39    async fn delete_stream(&self, name: &str) -> Result<()>;
40}