2017-08-04 14 views
1

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 RcBoxにそれを書いてください。私はこれらのことで間違った場所を探しているように感じる。

MyHandlerにも<'a>の有効期間が設定されている場合に発生します。ここでRustタイプのシステムについて私は誤解していますが、SqsClient<...>(と最終的にはRusotoの他のもの)への参照を自分の構造体に渡すために何ができるでしょうか?私が上にしようとしていることが慣用的な錆であるかどうかを知ることは有用であろう。そうでない場合は、代わりにどのようなパターンを使用する必要がありますか?

これはHow do I pass a struct with type parameters as a function argument?からのフォローアップです。

+0

この試し:残念ながら ' –

+0

@TiborBenke同じエラー:'構造体MyHandlerという<'a> {& 'SqsClient 、 sqsclient}を。私はあまり役に立たないように静的に試しました。 – Bojangles

答えて

2

解決済み! DispatchSignedRequestおよびProvideAwsCredentials(Rusotoから)は、形質である。

extern crate rusoto_core; 
extern crate hyper; 

use hyper::Client; 
use rusoto_sqs::{ Sqs, SqsClient }; 
use rusoto_core::{ DefaultCredentialsProvider }; 

struct MyHandler<'a> { 
    sqsclient: &'a SqsClient<DefaultCredentialsProvider, Client>, 
} 

impl<'a> Handler for MyHandler<'a> { 
    // ... 
} 

DefaultCredentialsProviderClient(ハイパー)から、両方の構造体ですので、今、このコードは罰金コンパイル:私は今のコードは次のようになり、それらの特性のimpl、すなわち構造体を使用する必要がありました。

ここでハイパー0.10を使用しています。ハイパー0.11では、Clientに異なるタイプの署名が必要です。