pub trait StaticFilter: Filter + Sized{
    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;

    // Required method
    fn try_from_config(
        config: Option<Self::Configuration>
    ) -> Result<Self, CreationError>;

    // Provided methods
    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, CreationError> { ... }
    fn as_filter_config(
        config: impl Into<Option<Self::Configuration>>
    ) -> Result<Filter, CreationError> { ... }
}
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;

/// Prepends data on each packet
#[async_trait::async_trait]
impl Filter for Greet {
    async fn read(&self, ctx: &mut ReadContext) -> Result<(), FilterError> {
        ctx.contents.prepend_from_slice(b"Hello ");
        Ok(())
    }
    async fn write(&self, ctx: &mut WriteContext) -> Result<(), FilterError> {
        ctx.contents.prepend_from_slice(b"Goodbye ");
        Ok(())
    }
}

impl StaticFilter for Greet {
    const NAME: &'static str = "greet.v1";
    type Configuration = ();
    type BinaryConfiguration = ();

    fn try_from_config(_: Option<Self::Configuration>) -> Result<Self, CreationError> {
        Ok(Self)
    }
}

Required Associated Types§

source

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.

source

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§

source

const NAME: &'static str

The globally unique name of the filter.

Required Methods§

source

fn try_from_config( config: Option<Self::Configuration> ) -> Result<Self, CreationError>

Instantiates a new StaticFilter from the given configuration, if any.

§Errors

If the provided configuration is invalid.

Provided Methods§

source

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.

source

fn factory() -> DynFilterFactory
where Self: 'static,

Creates a new dynamic FilterFactory virtual table.

source

fn ensure_config_exists( config: Option<Self::Configuration> ) -> Result<Self::Configuration, CreationError>

Convenience method for providing a consistent error message for filters which require a fully initialized Self::Configuration.

source

fn as_filter_config( config: impl Into<Option<Self::Configuration>> ) -> Result<Filter, CreationError>

Object Safety§

This trait is not object safe.

Implementors§

source§

impl StaticFilter for Capture

source§

const NAME: &'static str = "quilkin.filters.capture.v1alpha1.Capture"

§

type Configuration = Config

§

type BinaryConfiguration = Capture

source§

impl StaticFilter for Compress

source§

const NAME: &'static str = "quilkin.filters.compress.v1alpha1.Compress"

§

type Configuration = Config

§

type BinaryConfiguration = Compress

source§

impl StaticFilter for Concatenate

source§

const NAME: &'static str = "quilkin.filters.concatenate.v1alpha1.Concatenate"

§

type Configuration = Config

§

type BinaryConfiguration = Concatenate

source§

impl StaticFilter for Debug

source§

const NAME: &'static str = "quilkin.filters.debug.v1alpha1.Debug"

§

type Configuration = Config

§

type BinaryConfiguration = Debug

source§

impl StaticFilter for Drop

source§

const NAME: &'static str = "quilkin.filters.drop.v1alpha1.Drop"

§

type Configuration = Config

§

type BinaryConfiguration = Drop

source§

impl StaticFilter for Firewall

source§

const NAME: &'static str = "quilkin.filters.firewall.v1alpha1.Firewall"

§

type Configuration = Config

§

type BinaryConfiguration = Firewall

source§

impl StaticFilter for HashedTokenRouter

source§

const NAME: &'static str = "quilkin.filters.token_router.v1alpha1.HashedTokenRouter"

§

type Configuration = Config

§

type BinaryConfiguration = TokenRouter

source§

impl StaticFilter for LoadBalancer

source§

const NAME: &'static str = "quilkin.filters.load_balancer.v1alpha1.LoadBalancer"

§

type Configuration = Config

§

type BinaryConfiguration = LoadBalancer

source§

impl StaticFilter for LocalRateLimit

source§

const NAME: &'static str = "quilkin.filters.local_rate_limit.v1alpha1.LocalRateLimit"

§

type Configuration = Config

§

type BinaryConfiguration = LocalRateLimit

source§

impl StaticFilter for Match

source§

const NAME: &'static str = "quilkin.filters.match.v1alpha1.Match"

§

type Configuration = Config

§

type BinaryConfiguration = Match

source§

impl StaticFilter for Pass

source§

const NAME: &'static str = "quilkin.filters.pass.v1alpha1.Pass"

§

type Configuration = Config

§

type BinaryConfiguration = Pass

source§

impl StaticFilter for Timestamp

source§

const NAME: &'static str = "quilkin.filters.timestamp.v1alpha1.Timestamp"

§

type Configuration = Config

§

type BinaryConfiguration = Timestamp

source§

impl StaticFilter for TokenRouter

source§

const NAME: &'static str = "quilkin.filters.token_router.v1alpha1.TokenRouter"

§

type Configuration = Config

§

type BinaryConfiguration = TokenRouter