#tower-middleware #filter #tower #middleware #tower-service #fallthrough

tower-fallthrough-filter

A Tower middleware that gives controll to a defined service if the filter matches and otherwise falls through to the inner service

3 releases

0.0.3 Mar 2, 2024
0.0.2 Feb 29, 2024
0.0.1 Feb 29, 2024

#479 in Asynchronous

Download history 130/week @ 2024-02-23 252/week @ 2024-03-01 19/week @ 2024-03-08 2/week @ 2024-03-15 44/week @ 2024-03-29 12/week @ 2024-04-05 36/week @ 2024-04-12

92 downloads per month

MIT license

21KB
412 lines

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.

Dependencies

~1–1.4MB
~25K SLoC