tower-fallthrough-filter

Crates.iotower-fallthrough-filter
lib.rstower-fallthrough-filter
version0.0.3
sourcesrc
created_at2024-02-29 15:26:04.287566
updated_at2024-03-02 18:06:02.317976
descriptionA Tower middleware that gives controll to a defined service if the filter matches and otherwise falls through to the inner service.
homepagehttps://github.com/32byte/htmx-server
repositoryhttps://github.com/32byte/htmx-server
max_upload_size
id1157889
size58,146
byTe (32byte)

documentation

https://docs.rs/tower-fallthrough-filter

README

Tower Fallthrough Filter

Ever wanted to filter a Tower Service, but not abort the request when the filter doesn't match? Now you can!

Installation

Add this to your Cargo.toml:

[dependencies]
tower-fallthrough-filter = "*"

Or add it using the cargo command:

cargo add tower-fallthrough-filter

Example how to use

use tower_fallthrough_filter::{Filter, FilterLayer};

#[derive(Clone)]
struct MyFilter;

impl<T> Filter<T> for MyFilter {
    fn filter(&self, _: T) -> bool {
        // This can be any logic you want
        // and can depend on some state stored
        // in the filter itself.

        // When this function returns true, my_service
        // will be called, otherwise the request will
        // fall through to the next service.
        some_buisness_logic()
    }
}

let my_service = MyService::new();
let layer = FilterLayer::new(MyFilter, my_service);

// Now you can use the layer as a normal Tower Layer

Check the examples folder for more examples.

Commit count: 0

cargo fmt