pub trait SharedData {
// Required methods
fn get(
&self,
key: &str,
) -> Result<(Option<ByteString>, Option<OptimisticLockVersion>)>;
fn set(
&self,
key: &str,
value: &[u8],
version: Option<OptimisticLockVersion>,
) -> Result<()>;
}Expand description
An interface of the Envoy Shared Data API.
Basic usage of SharedData:
use envoy::host::SharedData;
let shared_data = SharedData::default();
let value = shared_data.get("shared_key")?;
shared_data.set("shared_key", b"shared value", None)?;Injecting SharedData into a HTTP Filter as a dependency:
use envoy::host::SharedData;
struct MyHttpFilter<'a> {
shared_data: &'a dyn SharedData,
}
impl<'a> MyHttpFilter<'a> {
/// Creates a new instance parameterized with a given [`SharedData`] implementation.
pub fn new(shared_data: &'a dyn SharedData) -> Self {
MyHttpFilter { shared_data }
}
/// Creates a new instance parameterized with the default [`SharedData`] implementation.
pub fn default() -> Self {
Self::new(SharedData::default())
}
}Required Methods§
Sourcefn get(
&self,
key: &str,
) -> Result<(Option<ByteString>, Option<OptimisticLockVersion>)>
fn get( &self, key: &str, ) -> Result<(Option<ByteString>, Option<OptimisticLockVersion>)>
Implementations§
Sourcepub fn default() -> &'static dyn SharedData
pub fn default() -> &'static dyn SharedData
Returns the default implementation that interacts with Envoy
through its ABI.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".