Skip to main content

plugins/
options.rs

1// Copyright 2023 Greptime Team
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 common_options::plugin_options::{PluginOptionsDeserializer, PluginOptionsSerializer};
16use serde::{Deserialize, Serialize};
17
18#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
19pub struct DummyOptions;
20
21#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
22pub enum PluginOptions {
23    Dummy(DummyOptions),
24}
25
26pub struct PluginOptionsList(pub Vec<PluginOptions>);
27
28impl PluginOptionsSerializer for PluginOptionsList {
29    fn serialize(&self) -> Result<String, serde_json::Error> {
30        if self.0.is_empty() {
31            Ok(String::new())
32        } else {
33            serde_json::to_string(&self.0)
34        }
35    }
36}
37pub struct PluginOptionsDeserializerImpl;
38
39impl PluginOptionsDeserializer<Vec<PluginOptions>> for PluginOptionsDeserializerImpl {
40    fn deserialize(&self, payload: &str) -> Result<Vec<PluginOptions>, serde_json::Error> {
41        if payload.is_empty() {
42            Ok(vec![])
43        } else {
44            serde_json::from_str(payload)
45        }
46    }
47}