Trait quilkin::filters::StaticFilter
source · [−]pub trait StaticFilter: Filter + Sizedwhere
Error: From<<Self::Configuration as TryFrom<Self::BinaryConfiguration>>::Error> + From<<Self::BinaryConfiguration as TryFrom<Self::Configuration>>::Error>,{
type Configuration: JsonSchema + Serialize + for<'de> Deserialize<'de> + TryFrom<Self::BinaryConfiguration>;
type BinaryConfiguration: Message + Default + TryFrom<Self::Configuration> + Send + Sync + Sized;
const NAME: &'static str;
fn try_from_config(
config: Option<Self::Configuration>
) -> Result<Self, Error>;
fn from_config(config: Option<Self::Configuration>) -> Self { ... }
fn factory() -> DynFilterFactory
where
Self: 'static,
{ ... }
fn ensure_config_exists(
config: Option<Self::Configuration>
) -> Result<Self::Configuration, Error> { ... }
fn as_filter_config(
config: impl Into<Option<Self::Configuration>>
) -> Result<Filter, Error> { ... }
}
Expand description
Statically safe version of Filter
, if you’re writing a Rust filter, you
should implement StaticFilter
in addition to Filter
, as
StaticFilter
guarantees all of the required properties through the type
system, allowing Quilkin take care of the virtual table boilerplate
automatically at compile-time.
use quilkin::filters::prelude::*;
struct Greet;
impl Filter for Greet {
fn read(&self, ctx: &mut ReadContext) -> Option<()> {
ctx.contents.splice(0..0, b"Hello ".into_iter().copied());
Some(())
}
fn write(&self, ctx: &mut WriteContext) -> Option<()> {
ctx.contents.splice(0..0, b"Goodbye ".into_iter().copied());
Some(())
}
}
impl StaticFilter for Greet {
const NAME: &'static str = "greet.v1";
type Configuration = ();
type BinaryConfiguration = ();
fn try_from_config(_: Option<Self::Configuration>) -> Result<Self, quilkin::filters::Error> {
Ok(Self)
}
}
Required Associated Types
sourcetype Configuration: JsonSchema + Serialize + for<'de> Deserialize<'de> + TryFrom<Self::BinaryConfiguration>
type Configuration: JsonSchema + Serialize + for<'de> Deserialize<'de> + TryFrom<Self::BinaryConfiguration>
The human-readable configuration of the filter. Must be serde
compatible, have a JSON schema, and be convertible to and
from Self::BinaryConfiguration
.
sourcetype BinaryConfiguration: Message + Default + TryFrom<Self::Configuration> + Send + Sync + Sized
type BinaryConfiguration: Message + Default + TryFrom<Self::Configuration> + Send + Sync + Sized
The binary configuration of the filter. Must be prost
compatible,
and be convertible to and from Self::Configuration
.
Required Associated Constants
Required Methods
sourcefn try_from_config(config: Option<Self::Configuration>) -> Result<Self, Error>
fn try_from_config(config: Option<Self::Configuration>) -> Result<Self, Error>
Instantiates a new StaticFilter
from the given configuration, if any.
Errors
If the provided configuration is invalid.
Provided Methods
sourcefn from_config(config: Option<Self::Configuration>) -> Self
fn from_config(config: Option<Self::Configuration>) -> Self
Instantiates a new StaticFilter
from the given configuration, if any.
Panics
If the provided configuration is invalid.
sourcefn factory() -> DynFilterFactorywhere
Self: 'static,
fn factory() -> DynFilterFactorywhere
Self: 'static,
Creates a new dynamic FilterFactory
virtual table.
sourcefn ensure_config_exists(
config: Option<Self::Configuration>
) -> Result<Self::Configuration, Error>
fn ensure_config_exists(
config: Option<Self::Configuration>
) -> Result<Self::Configuration, Error>
Convenience method for providing a consistent error message for filters
which require a fully initialized Self::Configuration
.