grafbase_sdk/types/configuration.rs
1use serde::Deserialize;
2
3use crate::{cbor, SdkError};
4
5/// Configuration data for the extension, from the gateway toml config.
6pub struct Configuration(Vec<u8>);
7
8impl Configuration {
9 /// Creates a new `Configuration` from a CBOR byte vector.
10 pub(crate) fn new(config: Vec<u8>) -> Self {
11 Self(config)
12 }
13
14 /// Deserializes the configuration bytes into the requested type.
15 ///
16 /// # Errors
17 ///
18 /// Returns an error if deserialization fails.
19 pub fn deserialize<'de, T>(&'de self) -> Result<T, SdkError>
20 where
21 T: Deserialize<'de>,
22 {
23 cbor::from_slice(&self.0).map_err(Into::into)
24 }
25}