pdk_classy/extract/
config.rs

1// Copyright (c) 2025, Salesforce, Inc.,
2// All rights reserved.
3// For full license text, see the LICENSE.txt file
4
5//! Extractors are used to extract data from the context.
6
7use std::convert::Infallible;
8
9use super::{context::ConfigureContext, FromContext};
10
11#[derive(Clone, Debug, Hash)]
12/// The serialized configuration of the plugin
13pub struct Configuration(pub Vec<u8>);
14
15impl Default for Configuration {
16    fn default() -> Self {
17        Self("{}".as_bytes().to_vec())
18    }
19}
20
21impl FromContext<ConfigureContext> for Configuration {
22    type Error = Infallible;
23
24    fn from_context(context: &ConfigureContext) -> Result<Self, Self::Error> {
25        Ok(context
26            .host
27            .get_plugin_configuration()
28            .map(Configuration)
29            .unwrap_or_default())
30    }
31}