nautilus_persistence/writer/traits.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
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// -------------------------------------------------------------------------------------------------
15
16//! Shared writer sink trait declarations.
17
18use std::{any::Any, fmt::Debug};
19
20use nautilus_model::data::Data;
21
22/// Object-safe streaming sink boundary substitutable by streaming backends.
23pub trait StreamingSink: Debug {
24 /// Writes a single `Data` enum value.
25 /// # Errors
26 ///
27 /// Returns an error if the sink cannot serialize or persist the value.
28 fn write_data(&mut self, data: Data) -> anyhow::Result<()>;
29
30 /// Writes a batch of `Data` values.
31 /// # Errors
32 ///
33 /// Returns an error if any item cannot be serialized or persisted.
34 fn write_batch(&mut self, data: Vec<Data>) -> anyhow::Result<()>;
35
36 /// Writes any supported Nautilus message value.
37 /// # Errors
38 ///
39 /// Returns an error if the supported message cannot be serialized or persisted.
40 fn write_any(&mut self, message: &dyn Any) -> anyhow::Result<bool>;
41
42 /// Flushes buffered data to durable storage.
43 /// # Errors
44 ///
45 /// Returns an error if buffered data cannot be flushed.
46 fn flush(&mut self) -> anyhow::Result<()>;
47
48 /// Closes sink after flushing buffered data.
49 /// # Errors
50 ///
51 /// Returns an error if flushing or closing the sink fails.
52 fn close(&mut self) -> anyhow::Result<()>;
53}
54
55/// Boxed streaming sink trait object.
56pub type StreamingDataSink = Box<dyn StreamingSink>;