首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Warp中创建变量路径?

如何在Warp中创建变量路径?
EN

Stack Overflow用户
提问于 2019-07-05 10:25:29
回答 1查看 333关注 0票数 2

我正在尝试在Warp中有一个可变的路径。我已经尝试过了:

代码语言:javascript
复制
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));
}

但是我得到了一个错误:

代码语言:javascript
复制
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`

让path参数具有'static生存期的最佳方法是什么?

EN

回答 1

Stack Overflow用户

发布于 2019-07-05 22:28:12

您可以通过泄漏静态字符串来从分配的字符串中获取该字符串。

代码语言:javascript
复制
let uuid_str = Box::leak(uuid.to_string().into_boxed_str());
let hello = warp::path(uuid_str).map(|| "hello world");
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56895824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档