3

I'd like to build a custom path, then download a file at that path. Eg,

        warp::path!("files" / u32)
            .map(|fileId| {
                format!("{}.txt", *FILES_PATH, fileId)
            })
            .and(warp::fs::file)

But I get an error like:

the trait bound 'fn(_) -> 
    impl warp::filter::FilterClone {
      warp::filters::fs::file::<_>
    }: warp::filter::FilterBase' is not satisfied

Am I missing an easy way that this can be done?

Peter Burns
  • 44,401
  • 7
  • 38
  • 56
MrBigglesworth
  • 350
  • 1
  • 8

1 Answers1

3

In warp, filters cannot be dynamically generated, they must be created when the program starts up. There is a pull request to support this, but it hasn't seen activity in a while.

Your best option is to copy Warp's implementation of file paths - it uses Warp-internal code, so you'd have to define your own error and rejection types, but that's not too difficult.

Sabrina Jewson
  • 1,478
  • 1
  • 10
  • 17
  • Hm, is it true that there isn't a facility to write custom filters? The FilterBase trait seems to be private. Is this something one should use `.and_then` for? – Peter Burns Oct 30 '20 at 22:03
  • 1
    Yes, custom filters must be implemented with `and_then` and `impl Filter`. – Sabrina Jewson Oct 31 '20 at 10:25