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?
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.