{"id":368959,"date":"2024-05-21T03:53:07","date_gmt":"2024-05-21T03:53:07","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=368959"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=368959","title":{"rendered":"<span>\u041e\u0431\u0437\u043e\u0440 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Actix \u0432 Rust<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/771\/97f\/d2b\/77197fd2bb8ef232e881063bb7b6645d.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/771\/97f\/d2b\/77197fd2bb8ef232e881063bb7b6645d.png\"\/><\/figure>\n<p><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em><\/p>\n<p><strong>Actix<\/strong> \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043d\u0430 \u0441\u0432\u0435\u0442 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u041d\u0438\u043a\u043e\u043b\u0430\u044e \u041a\u0438\u043c\u0443, \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0434 \u043d\u0438\u043a\u043e\u043c <a href=\"https:\/\/github.com\/fafhrd91\">fafhrd91<\/a>. \u041d\u0438\u043a\u043e\u043b\u0430\u0439 \u0441\u043e\u0437\u0434\u0430\u043b \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0435, \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b. Actix \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0430\u043a\u0442\u043e\u0440\u043e\u0432, \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u044b\u043b\u0430 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0430 \u0432 1973 \u0433\u043e\u0434\u0443 \u0434\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445.<\/p>\n<p>Actix \u0442\u0440\u0435\u0431\u0443\u0435\u0442 Rust \u0432\u0435\u0440\u0441\u0438\u0438 1.39 \u0438\u043b\u0438 \u0432\u044b\u0448\u0435. \u041c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c Actix \u044e\u0437\u0430\u044f Cargo. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 Actix-web \u0432 \u0444\u0430\u0439\u043b <code>Cargo.toml<\/code> \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"yaml\">[dependencies] actix-web = \"4.0\"<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044e\u0437\u0430\u0435\u043c <code>cargo build<\/code>, \u0438 \u043a\u0430\u0440\u0433\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u043e\u043c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442 Actix Web \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438. <\/p>\n<h4>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 <\/h4>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b Actix &#8212; \u044d\u0442\u043e \u0430\u043a\u0442\u043e\u0440\u044b, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0438 \u0430\u0440\u0431\u0438\u0442\u0440.<\/p>\n<p><strong>\u0410\u043a\u0442\u043e\u0440<\/strong> \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u041e\u043d \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"rust\">use actix::prelude::*;  struct MyActor; impl Actor for MyActor {     type Context = Context&lt;Self>; }  impl MyActor {     fn new() -> Self {         MyActor     } }<\/code><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0430\u043a\u0442\u043e\u0440 \u0432 Actix \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0435\u0439\u0442 <code>Actor<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0430\u043a\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p><strong>System<\/strong> \u0432 Actix \u2014 \u044d\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438.<\/p>\n<pre><code class=\"rust\">fn main() {     let system = System::new();     system.block_on(async {         let addr = MyActor::new().start();         \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0430\u043a\u0442\u043e\u0440\u0443 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438     }); }<\/code><\/pre>\n<p><strong>Arbiter<\/strong> \u2014 \u044d\u0442\u043e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u043f\u0443\u043b\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u041a\u0430\u0436\u0434\u044b\u0439 <code>Arbiter<\/code> \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u043a\u0442\u043e\u0440\u043e\u0432, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0438\u0445 \u0437\u0430\u0434\u0430\u0447:<\/p>\n<pre><code class=\"rust\">fn main() {     let system = System::new();     system.block_on(async {         let arbiter = Arbiter::new();         arbiter.spawn(async {             \/\/ \u0437\u0430\u0434\u0430\u0447\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043d\u043e\u0432\u043e\u0433\u043e Arbiter         });     }); }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442:<\/p>\n<pre><code class=\"rust\">use actix::prelude::*;  struct Ping; impl Message for Ping {     type Result = String; }  struct PongActor; impl Actor for PongActor {     type Context = Context&lt;Self>; }  impl Handler&lt;Ping> for PongActor {     type Result = String;      fn handle(&amp;mut self, _msg: Ping, _ctx: &amp;mut Context&lt;Self>) -> Self::Result {         \"Pong\".to_string()     } }  fn main() {     let system = System::new();     system.block_on(async {         let pong_actor_address = PongActor.start();         let result = pong_actor_address.send(Ping).await.unwrap();         println!(\"Received: {}\", result);     }); }<\/code><\/pre>\n<p><strong>PongActor<\/strong> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>Ping<\/code> \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c &#171;Pong&#187;. C\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u043a\u0442\u043e\u0440\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u043c\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442\u0430. <\/p>\n<p><strong>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438<\/strong> \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0438\u043b\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u043c API. \u0412 Actix Web \u0434\u043b\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0440\u043e\u0441 <code>#[get(\"\/path\")]<\/code>, <code>#[post(\"\/path\")]<\/code> \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 HTTP-\u043c\u0435\u0442\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"rust\">use actix_web::{web, App, HttpResponse, HttpServer, Responder};  async fn greet(req: web::HttpRequest) -> impl Responder {     let name = req.match_info().get(\"name\").unwrap_or(\"World\");     HttpResponse::Ok().body(format!(\"Hello, {}!\", name)) }<\/code><\/pre>\n<p><strong>\u041c\u0438\u0434\u043b\u0432\u0430\u0440\u0438<\/strong> \u0432 Actix Web \u043c\u043e\u0433\u0443\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0445 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u043b, \u043d\u043e \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0443:<\/p>\n<pre><code class=\"rust\">use actix_web::{middleware, App, HttpServer};  #[actix_web::main] async fn main() -> std::io::Result&lt;()> {     HttpServer::new(|| {         App::new()             .wrap(middleware::Logger::default()) \/\/ \u043c\u0438\u0434\u043b\u0432\u0430\u0440\u0438 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f             .service(\/* \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 *\/)     })     .bind(\"127.0.0.1:8080\")?     .run()     .await }<\/code><\/pre>\n<h4>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0432 Actix<\/h4>\n<p>\u0412 Actix \u043a\u0430\u0436\u0434\u044b\u0439 \u0430\u043a\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0438\u043c\u0435\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438. \u0410\u043a\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c, \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>async\/await<\/code> Rust:<\/p>\n<pre><code class=\"rust\">use actix::prelude::*;  struct MyAsyncActor; impl Actor for MyAsyncActor {     type Context = Context&lt;Self>; }  #[derive(Message)] #[rtype(result = \"String\")] struct MyMessage;  impl Handler&lt;MyMessage> for MyAsyncActor {     type Result = ResponseFuture&lt;String>;      fn handle(&amp;mut self, _msg: MyMessage, _ctx: &amp;mut Context&lt;Self>) -> Self::Result {         Box::pin(async {             \/\/ \u043a\u0430\u043a\u0430\u044f-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f             actix_rt::time::sleep(std::time::Duration::from_secs(1)).await;             \"Hello from async actor!\".to_string()         })     } }<\/code><\/pre>\n<p><code>MyAsyncActor<\/code> \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>MyMessage<\/code>, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>sleep<\/code>. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f <code>ResponseFuture&lt;String><\/code> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u043e \u0447\u0442\u043e \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e.<\/p>\n<p>\u0421 Actix \u043c\u043e\u0436\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0410\u043a\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>.send()<\/code> \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0434\u0440\u0443\u0433\u0438\u043c \u0430\u043a\u0442\u043e\u0440\u0430\u043c \u0438 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>await<\/code>:<\/p>\n<pre><code class=\"rust\">#[actix_rt::main] async fn main() {     let addr = MyAsyncActor.start();      let res = addr.send(MyMessage).await;     match res {         Ok(result) => println!(\"Received response: {}\", result),         Err(e) => println!(\"Encountered an error: {}\", e),     } }<\/code><\/pre>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>MyMessage<\/code> \u0430\u043a\u0442\u043e\u0440\u0443 <code>MyAsyncActor<\/code> \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442.<\/p>\n<p>Actix \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0442\u0440\u0438\u043c\u043e\u0432:<\/p>\n<pre><code class=\"rust\">use actix::prelude::*; use futures::stream::{self, StreamExt};  struct StreamActor; impl Actor for StreamActor {     type Context = Context&lt;Self>; }  impl StreamHandler&lt;i32> for StreamActor {     fn handle(&amp;mut self, item: i32, _ctx: &amp;mut Context&lt;Self>) {         println!(\"Received: {}\", item);     } }  #[actix_rt::main] async fn main() {     let addr = StreamActor.start();      \/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430     let stream = stream::iter(vec![1, 2, 3]);     \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u0442\u0440\u0438\u043c\u0430 \u0430\u043a\u0442\u043e\u0440\u0443     addr.add_stream(stream); }<\/code><\/pre>\n<p><code>StreamActor<\/code> \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0440\u0438\u043c \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<h4>\u041f\u0440\u043e\u0447\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u043c\u0443 \u043f\u0443\u0442\u0438 (<code>\/<\/code>):<\/p>\n<pre><code class=\"rust\">use actix_web::{web, App, HttpResponse, HttpServer, Responder};  async fn greet() -> impl Responder {     HttpResponse::Ok().body(\"Hello, Habr!\") }  #[actix_web::main] async fn main() -> std::io::Result&lt;()> {     HttpServer::new(|| {         App::new()             .route(\"\/\", web::get().to(greet))     })     .bind(\"127.0.0.1:8080\")?     .run()     .await }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c HTTP-\u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043b\u0443\u0448\u0430\u0435\u0442 \u043d\u0430 <code>127.0.0.1:8080<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>greet<\/code> \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 GET-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <code>\/<\/code>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>greet<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0443\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435:<\/p>\n<pre><code class=\"rust\">use actix_web::{web, App, HttpResponse, HttpServer, Responder};  async fn greet_user(name: web::Path&lt;String>) -> impl Responder {     HttpResponse::Ok().body(format!(\"Zdarova, {}!\", name)) }  #[actix_web::main] async fn main() -> std::io::Result&lt;()> {     HttpServer::new(|| {         App::new()             .route(\"\/greet\/{name}\", web::get().to(greet_user))     })     .bind(\"127.0.0.1:8080\")?     .run()     .await }<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>web::Path<\/code> \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <code>name<\/code> \u0438\u0437 \u043f\u0443\u0442\u0438 URL \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Actix-web \u0447\u0430\u0441\u0442\u043e \u044e\u0437\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 ORM, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>Diesel<\/code> \u0438\u043b\u0438 <code>sqlx<\/code>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c<code>sqlx<\/code> \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0431\u0434\u0448\u043a\u043e\u0439 PostgreSQL:<\/p>\n<pre><code class=\"rust\">use actix_web::{web, App, HttpResponse, HttpServer, Responder}; use sqlx::postgres::PgPoolOptions; use std::env;  async fn get_user(pool: web::Data&lt;sqlx::PgPool>) -> impl Responder {     let row: (String,) = sqlx::query_as(\"SELECT name FROM users WHERE id = $1\")         .bind(1)         .fetch_one(&amp;**pool)         .await         .unwrap();      HttpResponse::Ok().body(format!(\"Hello, {}!\", row.0)) }  #[actix_web::main] async fn main() -> std::io::Result&lt;()> {     let database_url = env::var(\"DATABASE_URL\").expect(\"DATABASE_URL must be set\");     let pool = PgPoolOptions::new()         .connect(&amp;database_url)         .await         .expect(\"Failed to create pool.\");      HttpServer::new(move || {         App::new()             .app_data(web::Data::new(pool.clone()))             .route(\"\/user\", web::get().to(get_user))     })     .bind(\"127.0.0.1:8080\")?     .run()     .await }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043b\u0441\u044f \u043f\u0443\u043b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043a \u0431\u0434 PostgreSQL \u0438 \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0435\u0433\u043e \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0431\u0434 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 <code>get_user<\/code>.<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441 API. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 <code>reqwest<\/code>, \u043c\u043e\u0436\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c:<\/p>\n<pre><code class=\"rust\">use actix_web::{web, App, HttpResponse, HttpServer, Responder}; use reqwest::Client;  async fn fetch_data() -> impl Responder {     let client = Client::new();     let res = client.get(\"https:\/\/api.example.com\/data\")         .send()         .await         .unwrap()         .text()         .await         .unwrap();      HttpResponse::Ok().body(res) }  #[actix_web::main] async fn main() -> std::io::Result&lt;()> {     HttpServer::new(|| {         App::new()             .route(\"\/fetch\", web::get().to(fetch_data))     })     .bind(\"127.0.0.1:8080\")?     .run()     .await }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>fetch_data<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>reqwest<\/code> \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e API \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/p>\n<hr\/>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0436\u0435\u043b\u0430\u0435\u0442 \u0443\u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 &#8212; <a href=\"https:\/\/github.com\/actix\/actix-web\">Actix GitHub<\/a>.<\/p>\n<p><strong><em>\u0410 \u043f\u0440\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u042f\u041f \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0443\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u043e\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u044e\u0449\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 <\/em><\/strong><a href=\"https:\/\/otus.pw\/vJV4\/\"><strong><em>\u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u043e\u0432<\/em><\/strong><\/a><strong><em>.<\/em><\/strong><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/795565\/\"> https:\/\/habr.com\/ru\/articles\/795565\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em><\/p>\n<p><strong>Actix<\/strong> \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043d\u0430 \u0441\u0432\u0435\u0442 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u041d\u0438\u043a\u043e\u043b\u0430\u044e \u041a\u0438\u043c\u0443, \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0434 \u043d\u0438\u043a\u043e\u043c <a href=\"https:\/\/github.com\/fafhrd91\">fafhrd91<\/a>. \u041d\u0438\u043a\u043e\u043b\u0430\u0439 \u0441\u043e\u0437\u0434\u0430\u043b \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0435, \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0435 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b. Actix \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0430\u043a\u0442\u043e\u0440\u043e\u0432, \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u044b\u043b\u0430 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0430 \u0432 1973 \u0433\u043e\u0434\u0443 \u0434\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445.<\/p>\n<p>Actix \u0442\u0440\u0435\u0431\u0443\u0435\u0442 Rust \u0432\u0435\u0440\u0441\u0438\u0438 1.39 \u0438\u043b\u0438 \u0432\u044b\u0448\u0435. \u041c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c Actix \u044e\u0437\u0430\u044f Cargo. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 Actix-web \u0432 \u0444\u0430\u0439\u043b <code>Cargo.toml<\/code> \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"yaml\">[dependencies] actix-web = \"4.0\"<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044e\u0437\u0430\u0435\u043c <code>cargo build<\/code>, \u0438 \u043a\u0430\u0440\u0433\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u043e\u043c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442 Actix Web \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438. <\/p>\n<h4>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 <\/h4>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b Actix &#8212; \u044d\u0442\u043e \u0430\u043a\u0442\u043e\u0440\u044b, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0438 \u0430\u0440\u0431\u0438\u0442\u0440.<\/p>\n<p><strong>\u0410\u043a\u0442\u043e\u0440<\/strong> \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435. \u041e\u043d \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"rust\">use actix::prelude::*;  struct MyActor; impl Actor for MyActor {     type Context = Context&lt;Self>; }  impl MyActor {     fn new() -> Self {         MyActor     } }<\/code><\/pre>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0430\u043a\u0442\u043e\u0440 \u0432 Actix \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0435\u0439\u0442 <code>Actor<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0430\u043a\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p><strong>System<\/strong> \u0432 Actix \u2014 \u044d\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438.<\/p>\n<pre><code class=\"rust\">fn main() {     let system = System::new();     system.block_on(async {         let addr = MyActor::new().start();         \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0430\u043a\u0442\u043e\u0440\u0443 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438     }); }<\/code><\/pre>\n<p><strong>Arbiter<\/strong> \u2014 \u044d\u0442\u043e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u043f\u0443\u043b\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u041a\u0430\u0436\u0434\u044b\u0439 <code>Arbiter<\/code> \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u043a\u0442\u043e\u0440\u043e\u0432, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0438\u0445 \u0437\u0430\u0434\u0430\u0447:<\/p>\n<pre><code class=\"rust\">fn main() {     let system = System::new();     system.block_on(async {         let arbiter = Arbiter::new();         arbiter.spawn(async {             \/\/ \u0437\u0430\u0434\u0430\u0447\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043d\u043e\u0432\u043e\u0433\u043e Arbiter         });     }); }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u0441\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442:<\/p>\n<pre><code class=\"rust\">use actix::prelude::*;  struct Ping; impl Message for Ping {     type Result = String; }  struct PongActor; impl Actor for PongActor {     type Context = Context&lt;Self>; }  impl Handler&lt;Ping> for PongActor {     type Result = String;      fn handle(&amp;mut self, _msg: Ping, _ctx: &amp;mut Context&lt;Self>) -> Self::Result {         \"Pong\".to_string()     } }  fn main() {     let system = System::new();     system.block_on(async {         let pong_actor_address = PongActor.start();         let result = pong_actor_address.send(Ping).await.unwrap();         println!(\"Received: {}\", result);     }); }<\/code><\/pre>\n<p><strong>PongActor<\/strong> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>Ping<\/code> \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c &#171;Pong&#187;. C\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u043a\u0442\u043e\u0440\u0430, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u043c\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442\u0430. <\/p>\n<p><strong>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438<\/strong> \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0438\u043b\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u043c API. \u0412 Actix Web \u0434\u043b\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0440\u043e\u0441 <code>#[get(\"\/path\")]<\/code>, <code>#[post(\"\/path\")]<\/code> \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 HTTP-\u043c\u0435\u0442\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"rust\">use actix_web::{web, App, HttpResponse, HttpServer, Responder};  async fn greet(req: web::HttpRequest) -> impl Responder {     let name = req.match_info().get(\"name\").unwrap_or(\"World\");     HttpResponse::Ok().body(format!(\"Hello, {}!\", name)) }<\/code><\/pre>\n<p><strong>\u041c\u0438\u0434\u043b\u0432\u0430\u0440\u0438<\/strong> \u0432 Actix Web \u043c\u043e\u0433\u0443\u0442 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438\u0445 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u043b, \u043d\u043e \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0443:<\/p>\n<pre><code class=\"rust\">use actix_web::{middleware, App, HttpServer};  #[actix_web::main] async fn main() -> std::io::Result&lt;()> {     HttpServer::new(|| {         App::new()             .wrap(middleware::Logger::default()) \/\/ \u043c\u0438\u0434\u043b\u0432\u0430\u0440\u0438 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f             .service(\/* \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 *\/)     })     .bind(\"127.0.0.1:8080\")?     .run()     .await }<\/code><\/pre>\n<h4>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0432 Actix<\/h4>\n<p>\u0412 Actix \u043a\u0430\u0436\u0434\u044b\u0439 \u0430\u043a\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0438\u043c\u0435\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438. \u0410\u043a\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c, \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>async\/await<\/code> Rust:<\/p>\n<pre><code class=\"rust\">use actix::prelude::*;  struct MyAsyncActor; impl Actor for MyAsyncActor {     type Context = Context&lt;Self>; }  #[derive(Message)] #[rtype(result = \"String\")] struct MyMessage;  impl Handler&lt;MyMessage> for MyAsyncActor {     type Result = ResponseFuture&lt;String>;      fn handle(&amp;mut self, _msg: MyMessage, _ctx: &amp;mut Context&lt;Self>) -> Self::Result {         Box::pin(async {             \/\/ \u043a\u0430\u043a\u0430\u044f-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f             actix_rt::time::sleep(std::time::Duration::from_secs(1)).await;             \"Hello from async actor!\".to_string()         })     } }<\/code><\/pre>\n<p><code>MyAsyncActor<\/code> \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>MyMessage<\/code>, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>sleep<\/code>. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f <code>ResponseFuture&lt;String><\/code> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u043e \u0447\u0442\u043e \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e.<\/p>\n<p>\u0421 Actix \u043c\u043e\u0436\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0430\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0410\u043a\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>.send()<\/code> \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0434\u0440\u0443\u0433\u0438\u043c \u0430\u043a\u0442\u043e\u0440\u0430\u043c \u0438 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>await<\/code>:<\/p>\n<pre><code class=\"rust\">#[actix_rt::main] async fn main() {     let addr = MyAsyncActor.start();      let res = addr.send(MyMessage).await;     match res {         Ok(result) => println!(\"Received response: {}\", result),         Err(e) => println!(\"Encountered an error: {}\", e),     } }<\/code><\/pre>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>MyMessage<\/code> \u0430\u043a\u0442\u043e\u0440\u0443 <code>MyAsyncActor<\/code> \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442.<\/p>\n<p>Actix \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0441\u0442\u0440\u0438\u043c\u043e\u0432:<\/p>\n<pre><code class=\"rust\">use actix::prelude::*; use futures::stream::{self, StreamExt};  struct StreamActor; impl Actor for StreamActor {     type Context = Context&lt;Self>; }  impl StreamHandler&lt;i32> for StreamActor {     fn handle(&amp;mut self, item: i32, _ctx: &amp;mut Context&lt;Self>) {         println!(\"Received: {}\", item);     } }  #[actix_rt::main] async fn main() {     let addr = StreamActor.start();      \/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0441\u0442\u0440\u0438\u043c\u0430     let stream = stream::iter(vec![1, 2, 3]);     \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0441\u0442\u0440\u0438\u043c\u0430 \u0430\u043a\u0442\u043e\u0440\u0443     addr.add_stream(stream); }<\/code><\/pre>\n<p><code>StreamActor<\/code> \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0440\u0438\u043c \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u043e\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<h4>\u041f\u0440\u043e\u0447\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u043c\u0443 \u043f\u0443\u0442\u0438 (<code>\/<\/code>):<\/p>\n<pre><code class=\"rust\">use actix_web::{web, App, HttpResponse, HttpServer, Responder};  async fn greet() -> impl Responder {     HttpResponse::Ok().body(\"Hello, Habr!\") }  #[actix_web::main] async fn main() -> std::io::Result&lt;()> {     HttpServer::new(|| {         App::new()             .route(\"\/\", web::get().to(greet))     })     .bind(\"127.0.0.1:8080\")?     .run()     .await }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c HTTP-\u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043b\u0443\u0448\u0430\u0435\u0442 \u043d\u0430 <code>127.0.0.1:8080<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>greet<\/code> \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 GET-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <code>\/<\/code>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>greet<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0443\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435:<\/p>\n<pre><code class=\"rust\">use actix_web::{web, App, HttpResponse, HttpServer, Responder};  async fn greet_user(name: web::Path&lt;String>) -> impl Responder {     HttpResponse::Ok().body(format!(\"Zdarova, {}!\", name)) }  #[actix_web::main] async fn main() -> std::io::Result&lt;()> {     HttpServer::new(|| {         App::new()             .route(\"\/greet\/{name}\", web::get().to(greet_user))     })     .bind(\"127.0.0.1:8080\")?     .run()     .await }<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>web::Path<\/code> \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <code>name<\/code> \u0438\u0437 \u043f\u0443\u0442\u0438 URL \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Actix-web \u0447\u0430\u0441\u0442\u043e \u044e\u0437\u0430\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 ORM, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>Diesel<\/code> \u0438\u043b\u0438 <code>sqlx<\/code>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c<code>sqlx<\/code> \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0431\u0434\u0448\u043a\u043e\u0439 PostgreSQL:<\/p>\n<pre><code class=\"rust\">use actix_web::{web, App, HttpResponse, HttpServer, Responder}; use sqlx::postgres::PgPoolOptions; use std::env;  async fn get_user(pool: web::Data&lt;sqlx::PgPool>) -> impl Responder {     let row: (String,) = sqlx::query_as(\"SELECT name FROM users WHERE id = $1\")         .bind(1)         .fetch_one(&amp;**pool)         .await         .unwrap();      HttpResponse::Ok().body(format!(\"Hello, {}!\", row.0)) }  #[actix_web::main] async fn main() -> std::io::Result&lt;()> {     let database_url = env::var(\"DATABASE_URL\").expect(\"DATABASE_URL must be set\");     let pool = PgPoolOptions::new()         .connect(&amp;database_url)         .await         .expect(\"Failed to create pool.\");      HttpServer::new(move || {         App::new()             .app_data(web::Data::new(pool.clone()))             .route(\"\/user\", web::get().to(get_user))     })     .bind(\"127.0.0.1:8080\")?     .run()     .await }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043b\u0441\u044f \u043f\u0443\u043b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u043a \u0431\u0434 PostgreSQL \u0438 \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0435\u0433\u043e \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0431\u0434 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 <code>get_user<\/code>.<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441 API. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 <code>reqwest<\/code>, \u043c\u043e\u0436\u043d\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c:<\/p>\n<pre><code class=\"rust\">use actix_web::{web, App, HttpResponse, HttpServer, Responder}; use reqwest::Client;  async fn fetch_data() -> impl Responder {     let client = Client::new();     let res = client.get(\"https:\/\/api.example.com\/data\")         .send()         .await         .unwrap()         .text()         .await         .unwrap();      HttpResponse::Ok().body(res) }  #[actix_web::main] async fn main() -> std::io::Result&lt;()> {     HttpServer::new(|| {         App::new()             .route(\"\/fetch\", web::get().to(fetch_data))     })     .bind(\"127.0.0.1:8080\")?     .run()     .await }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>fetch_data<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>reqwest<\/code> \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e API \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.<\/p>\n<hr\/>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0436\u0435\u043b\u0430\u0435\u0442 \u0443\u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 &#8212; <a href=\"https:\/\/github.com\/actix\/actix-web\">Actix GitHub<\/a>.<\/p>\n<p><strong><em>\u0410 \u043f\u0440\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u042f\u041f \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0443\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u043e\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u044e\u0449\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 <\/em><\/strong><a href=\"https:\/\/otus.pw\/vJV4\/\"><strong><em>\u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u043e\u0432<\/em><\/strong><\/a><strong><em>.<\/em><\/strong><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/795565\/\"> https:\/\/habr.com\/ru\/articles\/795565\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-368959","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/368959","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=368959"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/368959\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=368959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=368959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=368959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}