Как я могу создать переменную путь в Warp? - PullRequest
1 голос
/ 05 июля 2019

Я пытаюсь иметь переменный путь в Деформации.Я пробовал это:

use uuid::Uuid;
use warp::{self, Filter};

fn main() {
    let uuid = Uuid::new_v4();

    println!("{}", uuid);

    let hello = warp::path(&uuid.to_string()).map(|| "hello world");

    warp::serve(hello).run(([127, 0, 0, 1], 8080));
}

, но я получаю сообщение об ошибке:

error[E0716]: temporary value dropped while borrowed
 --> src/main.rs:9:29
  |
9 |     let hello = warp::path(&uuid.to_string()).map(|| "hello world");
  |                 ------------^^^^^^^^^^^^^^^^-                      - temporary value is freed at the end of this statement
  |                 |           |
  |                 |           creates a temporary which is freed while still in use
  |                 argument requires that borrow lasts for `'static`

Каков наилучший способ, чтобы параметр пути имел 'static время жизни?

1 Ответ

0 голосов
/ 05 июля 2019

Вы можете получить статическую строку из выделенной, пропустив ее.

let uuid_str = Box::leak(uuid.to_string().into_boxed_str());
let hello = warp::path(uuid_str).map(|| "hello world");
...