我想将对Rusoto SQS客户端的引用传递给WebSocket服务器结构,以将消息推送到SQS队列中。特性声明中的类型构造函数
为此,我有一个(幼稚)结构如下:
struct MyHandler {
sqsclient: &SqsClient<ProvideAwsCredentials, DispatchSignedRequest>,
}
这将产生错误:
error[E0106]: missing lifetime specifier
--> src/main.rs:29:13
|
29 | sqsclient: &SqsClient<ProvideAwsCredentials, DispatchSignedRequest>,
| ^expected lifetime parameter
我已尝试各种类型签名和寿命弄虚作假其中所有未能变化的水平,但我不断变化对相同的错误:
error[E0277]: the trait bound `rusoto_core::ProvideAwsCredentials + 'static: std::marker::Sized` is not satisfied
--> src/main.rs:29:2
|
29 | sqsclient: &'static SqsClient<ProvideAwsCredentials, DispatchSignedRequest>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `rusoto_core::ProvideAwsCredentials + 'static` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `rusoto_core::ProvideAwsCredentials + 'static`
= note: required by `rusoto_sqs::SqsClient`
error[E0277]: the trait bound `rusoto_core::DispatchSignedRequest + 'static: std::marker::Sized` is not satisfied
--> src/main.rs:29:2
|
29 | sqsclient: &'static SqsClient<ProvideAwsCredentials, DispatchSignedRequest>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `rusoto_core::DispatchSignedRequest + 'static` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `rusoto_core::DispatchSignedRequest + 'static`
= note: required by `rusoto_sqs::SqsClient`
我也试过wr应用它在Rc
和Box
无济于事。虽然我觉得我在这些地方看错了地方。
这种情况发生在给予MyHandler
和<'a>
寿命。我对这里的Rust类型系统有什么误解?我能做些什么来将SqsClient<...>
(以及其他来自Rusoto的其他内容)的引用传递给我自己的结构?知道我上面试图做的是惯用的Rust会很有用。如果不是,我应该使用什么样的模式呢?
这是从How do I pass a struct with type parameters as a function argument?的后续行动。
试试:'MyHandler的结构{<'a> sqsclient:&'一个SqsClient, }' –
@TiborBenke同样的错误不幸。我试过''静态'也无济于事。 – Bojangles