vector_config/external/
encoding_rs.rs

1use std::cell::RefCell;
2
3use encoding_rs::Encoding;
4use serde_json::Value;
5
6use crate::{
7    schema::{generate_string_schema, SchemaGenerator, SchemaObject},
8    Configurable, GenerateError, Metadata, ToValue,
9};
10
11impl Configurable for &'static Encoding {
12    // TODO: At some point, we might want to override the metadata to define a validation pattern that only matches
13    // valid character set encodings... but that would be a very large array of strings, and technically the Encoding
14    // Standard is a living standard, so... :thinkies:
15
16    fn referenceable_name() -> Option<&'static str> {
17        Some("encoding_rs::Encoding")
18    }
19
20    fn metadata() -> Metadata {
21        let mut metadata = Metadata::default();
22        metadata.set_description(
23            "An encoding as defined in the [Encoding Standard](https://encoding.spec.whatwg.org/).",
24        );
25        metadata
26    }
27
28    fn generate_schema(_: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> {
29        Ok(generate_string_schema())
30    }
31}
32
33impl ToValue for &'static Encoding {
34    fn to_value(&self) -> Value {
35        Value::String(self.name().into())
36    }
37}