fern_proxy_interfaces/lib.rs
1// SPDX-FileCopyrightText: Copyright © 2022 The Fern Authors <team@fernproxy.io>
2// SPDX-License-Identifier: Apache-2.0
3
4//!TODO(ppiotr3k): write crate documentation
5
6use async_trait::async_trait;
7use std::fmt::Debug;
8
9// Re-export.
10//TODO(ppiotr3k): consider a "scoped" config for Handler needs
11pub use config::Config as SQLHandlerConfig;
12
13/// A supertrait to abstract frontend and backend SQL Messages.
14// Note: this supertrait will be more valuable when enum variant types are available.
15pub trait SQLMessage: Debug + Send + Sync {}
16
17/// A trait defining an interface for handling `SQLMessage`s.
18///
19/// The default implementation is simply a passthrough. An `SQLMessageHandler`
20/// is of value when it applies a transformation to the processed `SQLMessage`.
21#[async_trait]
22pub trait SQLMessageHandler<M>: Debug + Send + Sync
23where
24 M: Send + Sync,
25{
26 /// Applies a transformation to an `SQLMessage`.
27 async fn process(&mut self, msg: M) -> M
28 where
29 M: SQLMessage + 'async_trait,
30 {
31 msg
32 }
33
34 fn new(config: &SQLHandlerConfig) -> Self
35 where
36 Self: Sized;
37}
38
39//TODO(ppiotr3k): do something about those tests
40#[cfg(test)]
41mod tests {
42 #[test]
43 fn it_works() {}
44}