melodium_share/
context.rs1use super::{Attributes, DataType, Identifier};
2use melodium_common::descriptor::Context as CommonContext;
3use serde::{Deserialize, Serialize};
4use std::collections::BTreeMap;
5
6#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
7#[cfg_attr(feature = "webassembly", derive(tsify::Tsify))]
8#[cfg_attr(feature = "webassembly", tsify(into_wasm_abi, from_wasm_abi))]
9pub struct Context {
10 pub identifier: Identifier,
11 pub documentation: String,
12 pub values: BTreeMap<String, DataType>,
13 pub attributes: Attributes,
14}
15
16impl From<&dyn CommonContext> for Context {
17 fn from(value: &dyn CommonContext) -> Self {
18 Self {
19 identifier: Identifier::from(value.identifier()),
20 documentation: value.documentation().to_string(),
21 values: value
22 .values()
23 .iter()
24 .map(|(name, datatype)| (name.clone(), DataType::from(datatype)))
25 .collect(),
26 attributes: value.attributes().into(),
27 }
28 }
29}