有没有办法将自定义文件路径传递给 warp::fs::file?

Is there a way to pass a custom file path to warp::fs::file?

我想建立一个自定义路径,然后在该路径下载一个文件。例如,

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

但我收到如下错误:

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

我是否缺少一种可以完成此操作的简单方法?

在warp中,过滤器不能动态生成,必须在程序启动时创建。有一个pull request支持这个,但是好久没看到了activity

您最好的选择是复制 Warp's implementation of file paths - 它使用 Warp-internal 代码,因此您必须定义自己的错误和拒绝类型,但这并不难。