- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何将具有非静态生命周期的对象传递给 Rocket 的 manage
?目前我有一些类似的东西:
fn foo<'a>(bar: Bar<'a>) -> Result<(), Error> {
rocket::ignite()
.manage(bar)
.mount("/", routes![index])
.launch();
Ok(())
}
但是我得到以下错误:
cannot infer an appropriate lifetime due to conflicting requirements
note: ...so that the expression is assignable:
expected bar::Bar<'_>
found bar::Bar<'a>
note: but, the lifetime must be valid for the static lifetime...
为了添加更多上下文,Bar
是一个包含盒装闭包的 struct
,这些闭包使用运行时参数进行初始化。 args 包含密码、 key 和 secret 等内容 - 实际代码是开源的,因此可以找到 here .它是 WIP,因此会发生变化,并不完全是最新的,但希望能为最终目标提供一个想法。
最佳答案
您不能使用非静态生命周期,因为 manage()
的签名字面意思是 Send + Sync + 'static
.其原因在 documentation for State 中说明。 :
The type being managed must be thread safe and sendable across thread boundaries. In other words, it must implement Send + Sync + 'static.
也就是说,由于(工作)线程可以随时访问托管状态,并且由于无法保证这些线程何时退出,因此托管状态必须至少与整个程序一样长;那是'static
.
您可以尝试更改您的 foo()
采取bar: Bar<'static>
而不是通用的生命周期,然后从那里开始工作。 'static
的要求通常并不像听起来那么糟糕,因为所有拥有的值(如 String::new()
)都是 'static
只要它们不包含对其他事物的引用。
如果您无法提供 Bar<'static>
, 你也许可以使用 Arc
而不是普通引用所以 Bar<'a>
变成 Bar
.这里的基本原理是 Bar
持有原子计数的引用而不是引用,所以持有 Bar
保证所有成员都活着 Bar
活着。这使得 Bar
'static
.
作为旁注:在考虑 'static
时可能会有所帮助某些类型的要求是 'static
不是否意味着该值实际上永远存在。这只是意味着值(value)可以永远存在。在你的例子中,State
无法强制其他线程不退出并销毁它们的值。因此 State
必须保证它所操作的所有值都可以与 State
一样长地存在。想要。仅当这些值为 'static
时才成立。在线程边界。
关于rust - 将非静态生命周期传递给 Rocket 的管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55924379/
我需要对 RocketChat 的前端做一些改动。我已经在 Ubuntu 16.04 上进行了手动安装,并且是 JS 生态系统的新手。只需编辑文件(例如 programs/server/package
我正在尝试重用 Rocket.Chat login 生成的相同 authToken API。 { "status": "success", "data": { "authTok
我正在尝试使用 REST API 登录我的 Rocket Chat 安装。登录调用成功返回,我收到了 AuthToken 和 userID。但我似乎无法绕过登录屏幕。换句话说,我想做的是使用我的应用程
我们想在我们的服务器(域)上使用 Rocket.chat 应用程序而不是 open.rocket.chat,但是当我们用我们的服务器 URL 替换 open.rocket.chat 时,我们收到如下错
我们选择 Rocket.Chat 作为我们团队交流的现成开源产品。 我们想要的只是能够在幕后完成登录部分,因此当用户访问 Rocket.Chat URL(或任何快捷方式/路由 URL 或其他)时,他将
我想知道是否可以拦截通过 Rocket.Chat“自定义脚本”管理部分收到的新消息 最佳答案 编辑/app/ui-message/client/message.js并将以下代码插入Template.m
我正在使用的Python版本是MacOS Sierra上的Python 2.7.13,并且我还将OpenCV 3与Python一起使用。 while True: frame = read_st
我在 ElementaryOS 上安装 Rocket.Chat 服务器时遇到问题。我尝试解压 tgz 文件,但出现错误。 列表: sudo apt-get install npm curl graph
我是 Rocket.Chat 的新手。我需要向 channel 发送消息。我已经获得授权了。当我阅读有关发送消息的文档时,我发现了 roomId 参数,但我不知道如何获取此 ID。我尝试在 Rocke
我尝试用 Rocket.rs 创建一个小网站& Handlebars 模板系统。我想创建一个全局布局并将我的内容包含在 中标签 这是我的代码 templates/ ├── layouts │ └
我试图为“MyConfig”结构实现 Responder 特性。但是我不知道如何创建可以从函数返回的Response(包括类型为String的body)。 我试过这段代码。 #[derive(De
这个问题在这里已经有了答案: How do I create a global, mutable singleton? (7 个答案) How can I pass a variable initi
我正在将来自外部服务的数据存储在本地缓存中,我想创建一个端点来返回当前缓存中的数据。 #![feature(proc_macro_hygiene, decl_macro)] #[macro_use]
我正在尝试创建一个将字符串返回给客户端的 Rocket 路由,但我无法让它工作。到目前为止,这就是我所拥有的: #![feature(plugin)] #![plugin(rocket_codegen
我尝试每晚安装 Rust 并编译 Rocket 的 hello_world 示例项目。我收到此错误: error[E0599]: no associated item named `Lifetime`
我正在使用 Rocket我正在尝试创建一个 Layout 结构。我已经实现了 serde::Serialize,因为文档说静态方法 Template::render 的第二个参数接受一个实现了 Ser
如何将具有非静态生命周期的对象传递给 Rocket 的 manage?目前我有一些类似的东西: fn foo(bar: Bar) -> Result { rocket::ignite()
文件上传不适用于 CentOS 中的 GridFS;文件上传卡在 0%。 我将其更改为文件系统,现在在重新启动服务后可以正常使用。 文件上传后具体存放在哪里? 附带问题:有人知道为什么 GridFS
为什么我应该考虑在我们的开发管道中使用 Rocket 而不是 Docker。我们想使用 docker 创建可测试的容器,但现在有 Rocket 假装知道同样的事情。如果我们想开始容器化,我们是否应该认
我正在尝试设置与 kubernetes 的 HA rocket 聊天。根据rocket chat HA guide ,火箭支持HA。我假设 StatefulSet应该用来支持这样的记录: ex
我是一名优秀的程序员,十分优秀!