RustでRESTサービスを作成します。 パート4:REST APIへの移行

前回 、データベースの更新を実装しました。



RESTインターフェースを作成するためだけに残ります。 やってみましょう。



はじめに



この部分はおそらく最も難しいでしょう-クロージャーとライフタイムの複雑さだけでなく、送信と同期のタイプを詳しく学習します。 別の方法で、私は彼女に「データをクローンしなければならない理由を掘り下げて調べる」というタイトルを付けていたでしょう。 Rustの薄いスポットに触れて、いくつかの明白なエラーの原因を示すという点で便利です。 あなたが徹底的に理解したいのであれば-ようこそ。



また、上記のコードについて理解していない場合や、説明自体が十分に明確でないように思われる場合は、遠慮なくコメントに書いてください。 著者は、コードが記述されたとおりの形で機能する理由を理解しようとして1分または30分を費やさず、説明のためにIRCとフォーラムに何度もアクセスしなければなりませんでした。



コード全体の概要



基本的に、「電話帳」サービスのREST APIを提供するWebサーバーを起動する新しいチームを追加します。 CRUDの標準アクセスポイントを提供する必要があります:GETレコード、GETレコード/ ID、POSTレコード、PUTレコード/ ID、DELETEレコード/ ID。 これを行うには、 Ironフレームワークのルーターを使用します 。 コードは次のとおりです。



コマンドコードを追加
"serve" => { let sdb = Arc::new(Mutex::new(db)); let mut router = router::Router::new(); { let sdb_ = sdb.clone(); router.get("/api/v1/records", move |req: &mut Request| handlers::get_records(sdb_.clone(), req)); } { let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); } { let sdb_ = sdb.clone(); router.post("/api/v1/records", move |req: &mut Request| handlers::add_record(sdb_.clone(), req)); } { let sdb_ = sdb.clone(); router.put("/api/v1/records/:id", move |req: &mut Request| handlers::update_record(sdb_.clone(), req)); } { let sdb_ = sdb.clone(); router.delete("/api/v1/records/:id", move |req: &mut Request| handlers::delete_record(sdb_.clone(), req)); } Iron::new(router).http("localhost:3000").unwrap(); }
      
      







このオプションは機能しますが、かなり貧弱に見えます。 改善するにはいくつかの方法がありますが、最初にここで何が起こっているのかを理解します。 そして、次のパートで書き直します。 ハンドラーの実装もまた考慮されます。



データベースをまとめます



上記のコードには、2行目から何か新しいことがあります。



  let sdb = Arc::new(Mutex::new(db));
      
      





dbはpostgres :: Connectionです。 このデータベースですべての作業が行われるオブジェクト。

ミューテックスでラップし、ミューテックスをアトミックリンクカウンターに入れます。



なんで? 現時点では、多くのスレッドからデータベースへの同期アクセスを提供することだけを忘れないでください。これには、ミューテックスを使用します。 そして、複数のスレッド間でオブジェクトの所有権を共有するために、参照カウンターを使用します。スレッドは異なるタイミングで死に、データベースは誰も必要としないときに破棄されます。



この制限はIronアーキテクチャの結果です。 Webサーバーは、複数のスレッドで複数の要求を並行して処理できます。



APIパスの定義



次に、GETリクエストのパスを定義します。



  let mut router = router::Router::new(); { let sdb_ = sdb.clone(); router.get("/api/v1/records", move |req: &mut Request| handlers::get_records(sdb_.clone(), req)); }
      
      





このために、 Router :: get()を使用します。 このメソッドは、パスのグロブテンプレート(この場合、可変コンポーネントなしでパス全体が厳密に設定されます)およびこのパスの要求ハンドラーを受け入れます。



タイプハンドラー



ハンドラーは、 Handler traitを実装する任意のタイプです。 このタイプは比較的単純に見えます。



 pub trait Handler: Send + Sync + Any { fn handle(&self, &mut Request) -> IronResult<Response>; }
      
      





1つのメソッドはハンドルであり、可変のリクエストリンクを受け入れ、IronResultにラップされたHTTPレスポンスを返します。



IronResultは、エラーがIron自体に特化した通常の結果です。



 type IronResult<T> = Result<T, IronError>; pub struct IronError { ... }
      
      





次に、型自体の定義を見てみましょう。



 pub trait Handler: Send + Sync + Any {
      
      





このようなコードはまだ見ていません。 ただし、ここでは定義の一部のみが新しくなっています。Send+ Sync + Anyです。



このエントリは、Handlerトレイトの実装には、Send、Sync、およびAnyトレイトの実装が必要であることを意味します。 そこで、Rustの柱であるSend and Syncに出会いました。 いずれもまだ私たちにとって興味深いものではありません。



送信と同期



同期から始めましょう。



Syncを実装する値は、複数のスレッドから同時に安全に変更できます。 データの競合はありません。



たとえば、 std :: sync :: atomic :: AtomicIsizeはアトミックアクセス整数です。 このタイプはSyncを実装しているため、複数のスレッドからAtomicIsize :: fetch_addを実行できます。



同期の詳細については、 こちらをご覧ください



同期アクセスは、値の所有権を別のスレッドに転送する可能性を意味しないことに注意してください。 同期を実装するタイプは、必ずしも送信を実装するとは限りません。



Sendの詳細 。 これは、他のスレッドに安全に渡すことができるタイプに実装された特性マーカーです。 たとえば、生のポインタを渡すことはできません。



 impl<T> !Send for *const T
      
      





!ここに送信するとは、「実装されていない特性」という意味です。



なぜこのような記録が必要なのですか? 次に、コンポーネントにSendが実装されている場合、そのSendはデフォルトですべてのタイプに実装されます。 フィールドがすべてSendである構造体もSendです(同期についても同じです)。 明らかに安全でないタイプは、このタイプの実装から「サブスクライブ解除」する必要があります。



Send(およびSync)の欠如も再帰的に伝播します。したがって、Sendを実装しない実装済みの型の内部で型を使用すると、デフォルトの型でも実装されません。



std :: sync :: atomic :: AtomicPtrはすでに他のスレッドに渡すことができます:



 impl<T> Send for AtomicPtr<T>
      
      





世帯レベルでは、これは、値を別のスレッドに与えることができることを意味します-例えば、 スレッド:: spawnを実行するとき。 ただし、これは多くのスレッドからのアクセスが同期されることを意味しません。 送信は、型を別のスレッドからアクセス可能なメモリに移動できるようにする必要があることのみを示します。



送信と同期はしばしば密接に関係します-1つの型を実装する型は、同時に他の型を実装します。 したがって、上記のAtomicPtrはハードウェアアトミック操作のラッパーであり、これにより、値を別のストリームに転送できるだけでなく、コンテンツへの安全な同時アクセスを実装できます。 AtomicPtrは同期されています-Syncも実装しています。



std :: sync :: mpsc ::送信者は他のストリームに渡すこともできます:



 impl<T: Send> Send for Sender<T>
      
      





ただし、Senderは型を別のスレッドに送信できる良い例ですが、それ自体は同期されません。 これは、チャネルの送信側を実装する構造です-対応するReceiver構造があります。 そのため、チャネルの作成後にSenderを送信側ストリームに転送できますが、多くのフローから1人のSenderへのアクセスは禁止されています。



エントリ<T:Send>は、チャネルを介して送信されるデータに対してデータ型を実装する必要があることを示します。 論理的です-データはチャネルを介して送信でき、原則として別のストリーム転送できるはずです。



送信タイプの詳細については、 こちらをご覧ください



素晴らしい、並べ替えの種類。



データベースをラップした理由



ArcとMutexをもう一度見てください。



 impl<T> Send for Arc<T> where T: Send + Sync + ?Sized impl<T> Sync for Arc<T> where T: Send + Sync + ?Sized impl<T: ?Sized + Send> Send for Mutex<T> impl<T: ?Sized + Send> Sync for Mutex<T>
      
      





そのため、dbをミューテックスでラップしました。これにより、添付された送信および同期データが同期され、別のストリームに送信されます。 そのようなデータのみをArcに配置できます。 アーク自体も再び同期され、別のストリームに送信できます。



大きさはまだ私たちには馴染みがありません-もう一度考えてみてください。



短絡



コードをもう一度見てみましょう。 ここにあります:



  let sdb = Arc::new(Mutex::new(db)); let mut router = router::Router::new(); { let sdb_ = sdb.clone(); router.get("/api/v1/records", move |req: &mut Request| handlers::get_records(sdb_.clone(), req)); }
      
      





.get()の2番目の引数はクロージャーです。 個別に考えてみましょう。



  move |req: &mut Request| handlers::get_records(sdb_.clone(), req));
      
      





引数から始めましょう-それらは垂直バーの中にあります。 可変のリクエストリンクである1つのreq引数を受け入れます。 覚えているように、Iron Handlerには署名が必要なので



 fn handle(&self, &mut Request) -> IronResult<Response>;
      
      





クロージャー本体は、ハンドラー:: get_recordsを呼び出すだけです。 環境の一部として、クロージャー引数とArc <Mutex>のコピーをこの関数に渡します。



なぜコピーですか? これが最も興味深いものになります。



データを複製しないようにしましょう



これを理解するために、コピーをクロージャーに渡さず、sdb_自体を渡した場合に何が起こるか考えてみましょう。 このように:



  { let sdb_ = sdb.clone(); router.get("/api/v1/records", move |req: &mut Request| handlers::get_records(sdb_, req)); }
      
      





rustcは何と言いますか?



 main.rs:120:32:122:69エラー:特性 `for <'r、' r、 'r> core :: ops :: Fn <(&' r mut iron :: request :: Request <'r 、 'r>、)> `タイプには実装されていません` [closure@main.rs:121:36:122:68 sdb_:alloc :: arc :: Arc <std :: sync :: mutex :: Mutex < postgres ::接続>>] `[E0277]
 main.rs:120 router.get( "/ api / v1 / records"、
 main.rs:121 move | req:&mut Request |
 main.rs:122ハンドラー:: get_records(sdb_、req));
 main.rs:120:32:122:69 help: `rustc --explain E0277`を実行して詳細な説明を表示します


どうやら、彼は非常に不満です。



エラーの本質は何ですか? 特性Fn(&mut Request)は、クロージャーには実装されていません。 これはどんなキャラクターですか?



クロージャーの実装の機能



これは、複数回呼び出すことができる障害に対して実装される特性です。 回路がトリガーされる回数を知ることが重要なのはなぜですか? 閉鎖から何かの所有物を移動する場合、これは一度しか実行できないためです。 次回、プロパティを移動する場所はなくなります。 この場合、クロージャーはFnOnceを実装しますが、Fnは実装しません。 コードでは、sdb_のコピーをハンドラー自体に移動します-ハンドラー:: get_records 彼は受け入れます Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




   Arc<Mutex>  .       ,    . 
      



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




   Arc<Mutex>  .       ,    . 
      



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




   Arc<Mutex>  .       ,    . 
      



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();

:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .








Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




   Arc<Mutex>  .       ,    . 
      



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




   Arc<Mutex>  .       ,    . 
      



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




   Arc<Mutex>  .       ,    . 
      



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();





? ! , Rust. , - Mutex Arc.



- .








Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .




Arc<Mutex> . , .



, ? Rust |x| x + 1 - . - , . .



Fn? , Handler Iron' Fn:



impl<F> Handler for F where F: Send + Sync + Any + Fn(&mut Request) -> IronResult<Response> { fn handle(&self, req: &mut Request) -> IronResult<Response> { (*self)(req) } }






where - . , F, Send + Sync + Any + Fn(&mut Request) -> IronResult.



, Handler Fn. Iron, , : - , .



Rust! .





- move . move , , . move :



main.rs:121:36: 122:76 error: closure may outlive the current function, but it borrows `sdb_`, which is owned by the current function [E0373] main.rs:121 |req: &mut Request| main.rs:122 handlers::get_records(sdb_.clone(), req)); main.rs:121:36: 122:76 help: run `rustc --explain E0373` to see a detailed explanation main.rs:122:58: 122:62 note: `sdb_` is borrowed here main.rs:122 handlers::get_records(sdb_.clone(), req)); ^~~~ main.rs:121:36: 122:76 help: to force the closure to take ownership of `sdb_` (and any other referenced variables), use the `move` keyword, as shown: main.rs: move |req: &mut Request| main.rs: handlers::get_records(sdb_.clone(), req)); error: aborting due to previous error

sdb_, main - Iron . , , , - main, .



Rust . .





: sdb ?



let sdb_ = sdb.clone();





:



main.rs:125:36: 125:39 error: use of moved value: `sdb` [E0382] main.rs:125 let sdb_ = sdb.clone(); ^~~ main.rs:125:36: 125:39 help: run `rustc --explain E0382` to see a detailed explanation main.rs:119:29: 119:33 note: `sdb` moved here because it has type `alloc::arc::Arc<std::sync::mutex::Mutex<postgres::Connection>>`, which is moved by default main.rs:119 let sdb_ = sdb; ^~~~

. , , GET/id:



{ let sdb_ = sdb.clone(); router.get("/api/v1/records/:id", move |req: &mut Request| handlers::get_record(sdb_.clone(), req)); }





:id, Router', URL , .



HTTP- Router' :



Iron::new(router).http("localhost:3000").unwrap();









? ! , Rust. , - Mutex Arc.



- .







All Articles