1use crate::proxy_wasm::types::Bytes;
8use crate::{
9 extract::{Extract, FromContext},
10 host::Host,
11 reactor::root::RootReactor,
12};
13use std::{convert::Infallible, rc::Rc};
14
15pub trait PropertyAccessor {
17 fn read_property(&self, path: &[&str]) -> Option<Bytes>;
19
20 fn set_property(&self, path: &[&str], value: Option<&[u8]>);
22}
23
24pub struct StreamProperties {
26 host: Rc<dyn Host>,
27}
28
29impl StreamProperties {
30 pub fn new(host: Rc<dyn Host>) -> Self {
31 Self { host }
32 }
33}
34
35impl PropertyAccessor for StreamProperties {
36 fn read_property(&self, path: &[&str]) -> Option<Bytes> {
37 self.host.get_property(path.to_vec())
38 }
39
40 fn set_property(&self, path: &[&str], value: Option<&[u8]>) {
41 self.host.set_property(path.to_vec(), value)
42 }
43}
44
45impl<C> FromContext<C> for StreamProperties
47where
48 Rc<dyn Host>: FromContext<C, Error = Infallible>,
49 Rc<RootReactor>: FromContext<C, Error = Infallible>,
50{
51 type Error = Infallible;
52
53 fn from_context(context: &C) -> Result<Self, Self::Error> {
54 let host = context.extract()?;
55 Ok(Self::new(host))
56 }
57}