为什么我不能使用多行构建器模式

Why can't I use a multi-line builder pattern

我几天前才开始研究 Rust(和 Warp)。我无法进入以下内容:

给定以下端点

    let hi = warp::path("hi");
    let bye = warp::path("bye");
    let howdy = warp::path("howdy");

下面为什么可以

    let routes = hi.or(bye).or(howdy);

但不是以下内容:

    let mut routes = hi.or(bye);
    routes = routes.or(howdy);

抛出编译错误:

error[E0308]: mismatched types 
   --> src/lib.rs:64:14
    |
63  |     let mut routes = hi.or(bye);
    |                      -------------------- expected due to this value
64  |     routes = routes.or(howdy);
    |              ^^^^^^^^^^^^^^^^ expected struct `warp::filter::and_then::AndThen`, found struct `warp::filter::or::Or` 

or() 包装成一种新类型。您可以使用阴影:

let routes = hi.or(bye);
let routes = routes.or(howdy);

如果你真的需要它们具有相同的类型(例如在循环中使用),你可以使用 boxed() 方法创建一个特征对象:

let mut routes = hi.or(bye).unify().boxed();
routes = routes.or(howdy).unify().boxed();