Skip to content

Commit

Permalink
perf: Use enum_dispatch over dynamic dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Oct 8, 2024
1 parent 5e1e5e7 commit 2be12e5
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 295 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ strum_macros = "0.26"
cfg-if = "1.0.0"
libflate = "2.0.0"
form_urlencoded = "1.2.1"
enum_dispatch = "0.3.13"

[dependencies.hyper-util]
version = "0.1"
Expand Down Expand Up @@ -236,4 +237,4 @@ schemars = { version = "0.8.15", features = ["bytes", "url"] }
url = { version = "2.4.1", features = ["serde"] }

[workspace.lints.clippy]
undocumented_unsafe_blocks = "deny"
undocumented_unsafe_blocks = "deny"
34 changes: 0 additions & 34 deletions examples/quilkin-filter-example/.gitignore

This file was deleted.

38 changes: 0 additions & 38 deletions examples/quilkin-filter-example/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions examples/quilkin-filter-example/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions examples/quilkin-filter-example/config.yaml

This file was deleted.

18 changes: 0 additions & 18 deletions examples/quilkin-filter-example/src/generated.rs

This file was deleted.

6 changes: 0 additions & 6 deletions examples/quilkin-filter-example/src/generated/greet.rs

This file was deleted.

26 changes: 0 additions & 26 deletions examples/quilkin-filter-example/src/greet.proto

This file was deleted.

115 changes: 0 additions & 115 deletions examples/quilkin-filter-example/src/main.rs

This file was deleted.

23 changes: 22 additions & 1 deletion src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,28 @@ pub use self::{
write::WriteContext,
};

use crate::test::TestFilter;

pub use self::chain::FilterChain;

#[enum_dispatch::enum_dispatch(Filter)]
pub enum FilterKind {
Capture,
Compress,
Concatenate,
Debug,
Drop,
Firewall,
LoadBalancer,
LocalRateLimit,
Pass,
Match,
Timestamp,
TokenRouter,
HashedTokenRouter,
TestFilter,
}

/// 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
Expand Down Expand Up @@ -104,7 +124,7 @@ pub use self::chain::FilterChain;
/// }
/// }
/// ```
pub trait StaticFilter: Filter + Sized
pub trait StaticFilter: Filter + Sized + Into<FilterKind>
// This where clause simply states that `Configuration`'s and
// `BinaryConfiguration`'s `Error` types are compatible with `filters::Error`.
where
Expand Down Expand Up @@ -207,6 +227,7 @@ where
/// `write` implementation to execute.
/// * Labels
/// * `filter` The name of the filter being executed.
#[enum_dispatch::enum_dispatch]
pub trait Filter: Send + Sync {
/// [`Filter::read`] is invoked when the proxy receives data from a
/// downstream connection on the listening port.
Expand Down
Loading

0 comments on commit 2be12e5

Please sign in to comment.