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

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

#834 in Asynchronous

Download history 12/week @ 2024-07-27 1/week @ 2024-08-03 7/week @ 2024-09-21 3/week @ 2024-09-28

89 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.5MB
~25K SLoC