我想將對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