json_utils/schema/
extra_props.rs1use std::collections::HashMap;
2
3use crate::json::JsValue;
4
5pub trait ExtraProps {
6 fn extra_props(&self) -> &HashMap<String, JsValue>;
7 fn extra_props_mut(&mut self) -> &mut HashMap<String, JsValue>;
8 fn with_extra_props(self, extra_props: HashMap<String, JsValue>) -> Self;
9}
10
11macro_rules! impl_extra_props {
12 ($type: ident, $field: ident) => {
13 impl $crate::schema::ExtraProps for $type {
14 fn extra_props(&self) -> &HashMap<String, JsValue> {
15 &self.$field
16 }
17
18 fn extra_props_mut(&mut self) -> &mut HashMap<String, JsValue> {
19 &mut self.$field
20 }
21
22 fn with_extra_props(self, extra_props: HashMap<String, JsValue>) -> Self {
23 Self {
24 $field: extra_props,
25 ..self
26 }
27 }
28 }
29 };
30}