{"id":371178,"date":"2024-05-21T04:42:13","date_gmt":"2024-05-21T04:42:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=371178"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=371178","title":{"rendered":"<span>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e Rust. 4\/4<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/fj\/yi\/qn\/fjyiqnduv3l-rdgxnbu_t_qpgxk.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/fj\/yi\/qn\/fjyiqnduv3l-rdgxnbu_t_qpgxk.jpeg\" data-blurred=\"true\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>Hello world!<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u0443\u044e \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u043f\u043e <a href=\"https:\/\/www.rust-lang.org\/ru\/\">Rust<\/a>.<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/790556\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/794941\/\">\u0412\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/796567\/\">\u0422\u0440\u0435\u0442\u044c\u044f \u0447\u0430\u0441\u0442\u044c<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/802609\/\">\u0411\u043e\u043d\u0443\u0441<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p><a href=\"https:\/\/my-js.org\/docs\/guide\/rust\/\">\u0414\u0440\u0443\u0433\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0432\u0430\u043c \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<p>\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u043d\u0430 <a href=\"https:\/\/google.github.io\/comprehensive-rust\/index.html\">Comprehensive Rust<\/a> \u2014 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435 \u043f\u043e <code>Rust<\/code> \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>Android<\/code> \u0432 <code>Google<\/code> \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043e \u043d\u0430 \u043b\u044e\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u0432\u043b\u0430\u0434\u0435\u044e\u0442 \u043b\u044e\u0431\u044b\u043c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0415\u0449\u0435 \u0440\u0430\u0437: \u044d\u0442\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043d\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043e \u043d\u0430 \u0442\u0435\u0445, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043a\u043e\u0434\u0438\u0442\u044c ?<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0442\u0435\u043c\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b (iterators): \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0432 \u0442\u0440\u0435\u0439\u0442 <code>Iterator<\/code><\/li>\n<li>\u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u044c<\/li>\n<li>\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/li>\n<li>\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a: \u043f\u0430\u043d\u0438\u043a\u0430, <code>Result<\/code> \u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>?<\/code><\/li>\n<li>\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 <code>Rust<\/code>: \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e <code>Rust<\/code> \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0435\u043c:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/doc.rust-lang.ru\/book\">\u041a\u043d\u0438\u0433\u0430\/\u0443\u0447\u0435\u0431\u043d\u0438\u043a \u043f\u043e Rust<\/a> (\u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435) \u2014 \u0433\u043b\u0430\u0432\u044b 7, 9, 11, 13, 14 \u0438 19<\/li>\n<li><a href=\"https:\/\/github.com\/rust-lang\/rustlings\">rustlings<\/a> \u2014 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f 10, 13, 15, 17 \u0438 18<\/li>\n<li><a href=\"https:\/\/doc.rust-lang.ru\/stable\/rust-by-example\/\">Rust \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445<\/a> (\u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435) \u2014 \u043f\u0440\u0438\u043c\u0435\u0440\u044b 10-12, 18, 21 \u0438 22<\/li>\n<li><a href=\"https:\/\/practice.rs\/why-exercise.html\">Rust by practice<\/a> \u2014 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f 13 \u0438 14<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u043c. <a href=\"https:\/\/my-js.org\/docs\/cheatsheet\/rust\/\">\u0411\u043e\u043b\u044c\u0448\u0443\u044e \u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0443 \u043f\u043e Rust<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"iteratory\">\u0418\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/h2>\n<p>  <\/p>\n<p><strong>Iterator<\/strong><\/p>\n<p>  <\/p>\n<p>\u0422\u0440\u0435\u0439\u0442 <a href=\"https:\/\/doc.rust-lang.org\/std\/iter\/trait.Iterator.html\">Iterator<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438. \u041e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <code>next<\/code> \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u041c\u043d\u043e\u0433\u0438\u0435 \u0442\u0438\u043f\u044b \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 <code>Iterator<\/code>, \u0438 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0445:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">struct Fibonacci {     curr: u32,     next: u32, }  impl Iterator for Fibonacci {     type Item = u32;      fn next(&amp;mut self) -> Option&lt;Self::Item> {         let new_next = self.curr + self.next;         self.curr = self.next;         self.next = new_next;         Some(self.curr)     } }  fn main() {     let fib = Fibonacci { curr: 0, next: 1 };     for (i, n) in fib.enumerate().take(5) {         println!(\"fib({i}): {n}\");     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u043c\u0430\u0440\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0442\u0440\u0435\u0439\u0442 <code>Iterator<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0434 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438 (<code>map<\/code>, <code>filter<\/code>, <code>reduce<\/code> \u0438 \u0442.\u0434.). \u0412 <code>Rust<\/code> \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u0441\u0442\u043e\u043b\u044c \u0436\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439, \u043a\u0430\u043a \u0438 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b\u0435 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/li>\n<li><code>IntoIterator<\/code> \u2014 \u044d\u0442\u043e \u0442\u0440\u0435\u0439\u0442, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0440\u0430\u0431\u043e\u0442\u0443 \u0446\u0438\u043a\u043b\u0430 <code>for<\/code>. \u041e\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0438\u043f\u0430\u043c\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a <code>Vec&lt;T><\/code>, \u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u043d\u0430 \u043d\u0438\u0445, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a <code>&amp;Vec&lt;T><\/code> \u0438 <code>&amp;[T]<\/code>. \u0414\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b (ranges) \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u044d\u0442\u043e\u0442 \u0442\u0440\u0435\u0439\u0442. \u0412\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>for i in some_vec { .. }<\/code>, \u043d\u043e <code>some_vec.next()<\/code> \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>IntoIterator<\/strong><\/p>\n<p>  <\/p>\n<p>\u0422\u0440\u0435\u0439\u0442 <code>Iterator<\/code> \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u043a\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430. \u0422\u0440\u0435\u0439\u0442 <a href=\"https:\/\/doc.rust-lang.org\/std\/iter\/trait.IntoIterator.html\">IntoIterator<\/a> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0442\u0438\u043f\u0430. \u041e\u043d \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c <code>for<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">struct Grid {     x_coords: Vec&lt;u32>,     y_coords: Vec&lt;u32>, }  impl IntoIterator for Grid {     type Item = (u32, u32);     type IntoIter = GridIter;      fn into_iter(self) -> GridIter {         GridIter { grid: self, i: 0, j: 0 }     } }  struct GridIter {     grid: Grid,     i: usize,     j: usize, }  impl Iterator for GridIter {     type Item = (u32, u32);      fn next(&amp;mut self) -> Option&lt;(u32, u32)> {         if self.i >= self.grid.x_coords.len() {             self.i = 0;             self.j += 1;             if self.j >= self.grid.y_coords.len() {                 return None;             }         }         let res = Some((self.grid.x_coords[self.i], self.grid.y_coords[self.j]));         self.i += 1;         res     } }  fn main() {     let grid = Grid { x_coords: vec![3, 5, 7, 9], y_coords: vec![10, 20, 30, 40] };     for (x, y) in grid {         println!(\"point = {x}, {y}\");     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>IntoIterator<\/code> \u0434\u043e\u043b\u0436\u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c 2 \u0442\u0438\u043f\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>Item<\/code> \u2014 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f, \u0442\u0430\u043a\u043e\u0439 \u043a\u0430\u043a <code>i8<\/code><\/li>\n<li><code>IntoIter<\/code> \u2014 \u0442\u0438\u043f <code>Iterator<\/code>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>into_iter<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <code>IntoIter<\/code> \u0438 <code>Iter<\/code> \u0441\u0432\u044f\u0437\u0430\u043d\u044b: \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0442\u0438\u043f <code>Item<\/code>. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <code>Option&lt;Type><\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 <code>x<\/code> \u0438 <code>y<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <code>IntoIterator::into_iter<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u043b\u0430\u0434\u0435\u043d\u0438\u0435 (ownership) \u043d\u0430\u0434 <code>self<\/code>. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0434\u0432\u0430\u0436\u0434\u044b \u043f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c <code>grid<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>main<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u0448\u0438\u0442\u0435 \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043f\u0443\u0442\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>IntoIterator<\/code> \u0434\u043b\u044f <code>&amp;Grid<\/code> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 <code>Grid<\/code> \u0432 <code>GridIter<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432: <code>for e in some_vec<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u043b\u0430\u0434\u0435\u043d\u0438\u0435 \u043d\u0430\u0434 <code>some_vec<\/code> \u0438 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u0430. \u0414\u043b\u044f \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>for e in &amp;some_vec<\/code>.<\/p>\n<p>  <\/p>\n<p><strong>FromIterator<\/strong><\/p>\n<p>  <\/p>\n<p>\u0422\u0440\u0435\u0439\u0442 <a href=\"https:\/\/doc.rust-lang.org\/std\/iter\/trait.FromIterator.html\">FromIterator<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0438\u0437 <code>Iterator<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn main() {     let primes = vec![2, 3, 5, 7];     let prime_squares = primes.into_iter().map(|p| p * p).collect::&lt;Vec&lt;_>>();     println!(\"prime_squares: {prime_squares:?}\"); }<\/code><\/pre>\n<p>  <\/p>\n<p><code>Iterator<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn collect&lt;B>(self) -> B where     B: FromIterator&lt;Self::Item>,     Self: Sized<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 2 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <code>B<\/code> \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e turbofish: <code>some_iterator.collect::&lt;COLLECTION_TYPE>()<\/code>, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435. \u0421\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 <code>_<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <code>Rust<\/code> \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0442\u0438\u043f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e<\/li>\n<li>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u0432\u043e\u0434\u0430 \u0442\u0438\u043f\u043e\u0432: <code>let prime_squares: Vec&lt;_> = some_iterator.collect()<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>IntoIterator<\/code> \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u043b\u044f <code>Vec<\/code>, <code>HashMap<\/code> \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0438\u043f\u043e\u0432. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u0430\u043a\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043b\u0435\u0432\u044b\u0435 \u0432\u0435\u0449\u0438, \u0432\u0440\u043e\u0434\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>Iterator&lt;Item = Result&lt;V, E>><\/code> \u0432 <code>Result&lt;Vec&lt;V>, E><\/code><\/p>\n<p>  <\/p>\n<p><strong>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435: \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u0440\u0435\u0439\u0442\u0430 <a href=\"https:\/\/doc.rust-lang.org\/std\/iter\/trait.Iterator.html\">Iterator<\/a> \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0438 \u0441\u043e\u0431\u0435\u0440\u0438\u0442\u0435 (<code>collect<\/code>) \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043c\u0435\u0436\u0434\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 `values`, \u0441\u043c\u0435\u0449\u0435\u043d\u043d\u044b\u043c\u0438 \u043d\u0430 `offset`. \/\/ `values` \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u043a\u0440\u0443\u0433\u0443. \/\/ \/\/ \u042d\u043b\u0435\u043c\u0435\u043d\u0442 `n` \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 - `values[(n+offset)%len] - values[n]`. fn offset_differences&lt;N>(offset: usize, values: Vec&lt;N>) -> Vec&lt;N> where     N: Copy + std::ops::Sub&lt;Output = N>, {     todo!(\"\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0439 \u043c\u0435\u043d\u044f\") }  fn main() {     let res = offset_differences(1, vec![1, 3, 5, 7]);     println!(\"{:?}\", res); }  #[cfg(test)] mod tests {     use super::*;      #[test]     fn test_offset_one() {         assert_eq!(offset_differences(1, vec![1, 3, 5, 7]), vec![2, 2, 2, -6]);         assert_eq!(offset_differences(1, vec![1, 3, 5]), vec![2, 2, -4]);         assert_eq!(offset_differences(1, vec![1, 3]), vec![2, -2]);     }      #[test]     fn test_larger_offsets() {         assert_eq!(offset_differences(2, vec![1, 3, 5, 7]), vec![4, 4, -4, -4]);         assert_eq!(offset_differences(3, vec![1, 3, 5, 7]), vec![6, -2, -2, -2]);         assert_eq!(offset_differences(4, vec![1, 3, 5, 7]), vec![0, 0, 0, 0]);         assert_eq!(offset_differences(5, vec![1, 3, 5, 7]), vec![2, 2, 2, -6]);     }      #[test]     fn test_custom_type() {         assert_eq!(             offset_differences(1, vec![1.0, 11.0, 5.0, 0.0]),             vec![10.0, -6.0, -5.0, 1.0]         );     }      #[test]     fn test_degenerate_cases() {         assert_eq!(offset_differences(1, vec![0]), vec![0]);         assert_eq!(offset_differences(1, vec![1]), vec![0]);         let empty: Vec&lt;i32> = vec![];         assert_eq!(offset_differences(1, empty), vec![]);     } }<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"rust\">fn offset_differences&lt;N>(offset: usize, values: Vec&lt;N>) -> Vec&lt;N> where     N: Copy + std::ops::Sub&lt;Output = N>, {     let a = (&amp;values).into_iter();     let b = (&amp;values).into_iter().cycle().skip(offset);     a.zip(b).map(|(a, b)| *b - *a).take(values.len()).collect() }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h2 id=\"moduli\">\u041c\u043e\u0434\u0443\u043b\u0438<\/h2>\n<p>  <\/p>\n<p><strong>\u041c\u043e\u0434\u0443\u043b\u0438<\/strong><\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u0432\u0438\u0434\u0435\u043b\u0438, \u043a\u0430\u043a \u0431\u043b\u043e\u043a\u0438 <code>impl<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d (namespace) \u0434\u043b\u044f \u0442\u0438\u043f\u0430.<\/p>\n<p>  <\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, <code>mod<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438\u043c\u0435\u043d:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">mod foo {     pub fn do_something() {         println!(\"\u0432 \u043c\u043e\u0434\u0443\u043b\u0435 foo\");     } }  mod bar {     pub fn do_something() {         println!(\"\u0432 \u043c\u043e\u0434\u0443\u043b\u0435 bar\");     } }  fn main() {     foo::do_something();     bar::do_something(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u043c\u0430\u0440\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043f\u0430\u043a\u0435\u0442\u044b (packages) \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0444\u0430\u0439\u043b <code>Cargo.toml<\/code>, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0441\u0431\u043e\u0440\u043a\u0443 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u0440\u0435\u0439\u0442\u043e\u0432<\/li>\n<li>\u043a\u0440\u0435\u0439\u0442\u044b (crates) \u2014 \u044d\u0442\u043e \u0434\u0435\u0440\u0435\u0432\u043e \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u0433\u0434\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043a\u0440\u0435\u0439\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u043c \u0444\u0430\u0439\u043b\u043e\u043c, \u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u044b\u0439 \u043a\u0440\u0435\u0439\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443<\/li>\n<li>\u043c\u043e\u0434\u0443\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u0418\u0435\u0440\u0430\u0440\u0445\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/strong><\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043c\u043e\u0434\u0443\u043b\u044f, <code>Rust<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0444\u0430\u0439\u043b\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">mod garden;<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 <code>Rust<\/code>, \u0447\u0442\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043c\u043e\u0434\u0443\u043b\u044f <code>Garden<\/code> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <code>src\/garden.rs<\/code>. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u043c\u043e\u0434\u0443\u043b\u044c <code>Garden::vegetables<\/code> \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <code>src\/garden\/vegetables.rs<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 <code>crate<\/code> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>src\/lib.rs<\/code> (\u0434\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u043e\u0433\u043e \u043a\u0440\u0435\u0439\u0442\u0430)<\/li>\n<li><code>src\/main.rs<\/code> (\u0434\u043b\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u0440\u0435\u0439\u0442\u0430)<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u0438, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0432 \u0444\u0430\u0439\u043b\u0430\u0445, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e &#171;\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430&#187;. \u041e\u043d\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u044e\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u2014 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0434\u0443\u043b\u044c.<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/! This module implements the garden, including a highly performant germination \/\/! implementation.  \/\/ Re-export types from this module. pub use garden::Garden; pub use seeds::SeedPacket;  \/\/\/ Sow the given seed packets. pub fn sow(seeds: Vec&lt;SeedPacket>) {     todo!() }  \/\/\/ Harvest the produce in the garden that is ready. pub fn harvest(garden: &amp;mut Garden) {     todo!() }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u043c\u0430\u0440\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0434\u043e <code>Rust 2018<\/code> \u043c\u043e\u0434\u0443\u043b\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 <code>module\/mod.rs<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>module.rs<\/code>, \u0438 \u044d\u0442\u043e \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/li>\n<li>\u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f <code>filename.rs<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b <code>filename\/mod.rs<\/code> \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 <code>mod.rs<\/code> \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u043e \u0432 \u043d\u0438\u0445 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f<\/li>\n<li>\u043f\u0440\u0438 \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b\u043e\u043c:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"plaintext\">src\/ \u251c\u2500\u2500 main.rs \u251c\u2500\u2500 top_module.rs \u2514\u2500\u2500 top_module\/     \u2514\u2500\u2500 sub_module.rs<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u043c\u0435\u0441\u0442\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"rust\">#[path = \"some\/path.rs\"] mod some_module;<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u043c\u043e\u0434\u0443\u043b\u044f \u0432 \u0444\u0430\u0439\u043b \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>some_module_test.rs<\/code>.<\/p>\n<p>  <\/p>\n<p><strong>\u0412\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u044c<\/strong><\/p>\n<p>  <\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c\u0438\/\u0437\u0430\u043a\u0440\u044b\u0442\u044b\u043c\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e (\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0442 \u0434\u0435\u0442\u0430\u043b\u0438 \u0441\u0432\u043e\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438)<\/li>\n<li>\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0438 \u0438 \u0441\u0438\u0431\u043b\u0438\u043d\u0433\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0438\u0434\u0438\u043c\u044b\u043c\u0438 (\u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0434\u0443\u043b\u0435\u0439)<\/li>\n<li>\u0435\u0441\u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0432\u0438\u0434\u0438\u043c \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 <code>foo<\/code>, \u043e\u043d \u0432\u0438\u0434\u0438\u043c \u0432\u0441\u0435\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c <code>foo<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"rust\">mod outer {     fn private() {         println!(\"outer::private\");     }      pub fn public() {         println!(\"outer::public\");     }      mod inner {         fn private() {             println!(\"outer::inner::private\");         }          pub fn public() {             println!(\"outer::inner::public\");             super::private();         }     } }  fn main() {     outer::public(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u043c\u0430\u0440\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u043c\/\u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>pub<\/code><\/li>\n<li>\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 <a href=\"https:\/\/doc.rust-lang.org\/reference\/visibility-and-privacy.html#pubin-path-pubcrate-pubsuper-and-pubself\"><code>\u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b pub<\/code><\/a>, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>use, super, self<\/strong><\/p>\n<p>  <\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u0432 \u0441\u0432\u043e\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 <code>use<\/code>. \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use std::collections::HashSet; use std::process::abort;<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u041f\u0443\u0442\u0438<\/em><\/p>\n<p>  <\/p>\n<p>\u041f\u0443\u0442\u044c (path) \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041a\u0430\u043a \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0443\u0442\u044c:<br \/> \n<ul>\n<li><code>foo<\/code> \u0438\u043b\u0438 <code>self::foo<\/code> \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <code>foo<\/code> \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u0435<\/li>\n<li><code>super::foo<\/code> \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <code>foo<\/code> \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435<\/li>\n<\/ul>\n<\/li>\n<li>\u041a\u0430\u043a \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0439 \u043f\u0443\u0442\u044c:<br \/> \n<ul>\n<li><code>crate:foo<\/code> \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <code>foo<\/code> \u0432 \u043a\u043e\u0440\u043d\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043a\u0440\u0435\u0439\u0442\u0430<\/li>\n<li><code>bar::foo<\/code> \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <code>foo<\/code> \u0432 \u043a\u0440\u0435\u0439\u0442\u0435 <code>bar<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0420\u0435\u043c\u0430\u0440\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 \u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0444\u0430\u0439\u043b <code>lib.rs<\/code> \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"rust\">mod storage;  pub use storage::disk::DiskStorage; pub use storage::network::NetworkStorage;<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 <code>DiskStorage<\/code> \u0438 <code>NetworkStorage<\/code> \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u0434\u0440\u0443\u0433\u0438\u043c \u043a\u0440\u0435\u0439\u0442\u0430\u043c \u043f\u043e \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u043c\u0443 \u043f\u0443\u0442\u0438.<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e <code>use<\/code> (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c) \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u043c\u043e\u0434\u0443\u043b\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u0440\u0435\u0439\u0442\u0430, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0442\u0438\u043f, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u043e\u0442 \u0442\u0440\u0435\u0439\u0442, \u0443\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043d\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>read_to_string<\/code> \u0434\u043b\u044f \u0442\u0438\u043f\u0430, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0435\u0433\u043e \u0442\u0440\u0435\u0439\u0442 <code>Read<\/code>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e <code>use std::io::Read<\/code><\/li>\n<li>\u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0435 <code>use<\/code> \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0437\u043d\u0430\u043a: <code>use std::io::*<\/code>. \u0414\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435\u044f\u0441\u043d\u043e, \u043a\u0430\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u0438 \u044d\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435: \u043c\u043e\u0434\u0443\u043b\u0438 \u0434\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0438 \u0432\u044b \u0440\u0435\u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u0442\u0435 \u043a\u043e\u0434 &#171;\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430&#187; \u0438\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 &#171;\u041c\u0435\u0442\u043e\u0434\u044b \u0438 \u0442\u0440\u0435\u0439\u0442\u044b&#187; \u0432 \u043d\u0430\u0431\u043e\u0440 \u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u041e\u0431\u044b\u0447\u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0438\u043f \u0438\u043b\u0438 \u043d\u0430\u0431\u043e\u0440 \u0442\u0435\u0441\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0438\u043f \u0432\u0438\u0434\u0436\u0435\u0442\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">pub trait Widget {     fn width(&amp;self) -> usize;      fn draw_into(&amp;self, buffer: &amp;mut dyn std::fmt::Write);      fn draw(&amp;self) {         let mut buffer = String::new();         self.draw_into(&amp;mut buffer);         println!(\"{buffer}\");     } }  pub struct Label {     label: String, }  impl Label {     fn new(label: &amp;str) -> Label {         Label { label: label.to_owned() }     } }  pub struct Button {     label: Label, }  impl Button {     fn new(label: &amp;str) -> Button {         Button { label: Label::new(label) }     } }  pub struct Window {     title: String,     widgets: Vec&lt;Box&lt;dyn Widget>>, }  impl Window {     fn new(title: &amp;str) -> Window {         Window { title: title.to_owned(), widgets: Vec::new() }     }      fn add_widget(&amp;mut self, widget: Box&lt;dyn Widget>) {         self.widgets.push(widget);     }      fn inner_width(&amp;self) -> usize {         std::cmp::max(             self.title.chars().count(),             self.widgets.iter().map(|w| w.width()).max().unwrap_or(0),         )     } }  impl Widget for Window {     fn width(&amp;self) -> usize {         self.inner_width() + 4     }      fn draw_into(&amp;self, buffer: &amp;mut dyn std::fmt::Write) {         let mut inner = String::new();         for widget in &amp;self.widgets {             widget.draw_into(&amp;mut inner);         }          let inner_width = self.inner_width();          writeln!(buffer, \"+-{:-&lt;inner_width$}-+\", \"\").unwrap();         writeln!(buffer, \"| {:^inner_width$} |\", &amp;self.title).unwrap();         writeln!(buffer, \"+={:=&lt;inner_width$}=+\", \"\").unwrap();         for line in inner.lines() {             writeln!(buffer, \"| {:inner_width$} |\", line).unwrap();         }         writeln!(buffer, \"+-{:-&lt;inner_width$}-+\", \"\").unwrap();     } }  impl Widget for Button {     fn width(&amp;self) -> usize {         self.label.width() + 4     }      fn draw_into(&amp;self, buffer: &amp;mut dyn std::fmt::Write) {         let width = self.width();         let mut label = String::new();         self.label.draw_into(&amp;mut label);          writeln!(buffer, \"+{:-&lt;width$}+\", \"\").unwrap();         for line in label.lines() {             writeln!(buffer, \"|{:^width$}|\", &amp;line).unwrap();         }         writeln!(buffer, \"+{:-&lt;width$}+\", \"\").unwrap();     } }  impl Widget for Label {     fn width(&amp;self) -> usize {         self.label.lines().map(|line| line.chars().count()).max().unwrap_or(0)     }      fn draw_into(&amp;self, buffer: &amp;mut dyn std::fmt::Write) {         writeln!(buffer, \"{}\", &amp;self.label).unwrap();     } }  fn main() {     let mut window = Window::new(\"Rust GUI Demo 1.23\");     window.add_widget(Box::new(Label::new(\"This is a small text GUI demo.\")));     window.add_widget(Box::new(Button::new(\"Click me!\")));     window.draw(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">cargo init gui-modules cd gui-modules cargo run<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <code>src\/main.rs<\/code>, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u0432 \u043d\u0435\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>mod<\/code>, \u0438 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>src<\/code>.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"plaintext\">src \u251c\u2500\u2500 main.rs \u251c\u2500\u2500 widgets \u2502\u00a0\u00a0 \u251c\u2500\u2500 button.rs \u2502\u00a0\u00a0 \u251c\u2500\u2500 label.rs \u2502\u00a0\u00a0 \u2514\u2500\u2500 window.rs \u2514\u2500\u2500 widgets.rs<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ src\/widgets.rs mod button; mod label; mod window;  pub trait Widget {     fn width(&amp;self) -> usize;      fn draw_into(&amp;self, buffer: &amp;mut dyn std::fmt::Write);      fn draw(&amp;self) {         let mut buffer = String::new();         self.draw_into(&amp;mut buffer);         println!(\"{buffer}\");     } }  pub use button::Button; pub use label::Label; pub use window::Window;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ src\/widgets\/label.rs use super::Widget;  pub struct Label {     label: String, }  impl Label {     pub fn new(label: &amp;str) -> Label {         Label { label: label.to_owned() }     } }  impl Widget for Label {     fn width(&amp;self) -> usize {         self.label.lines().map(|line| line.chars().count()).max().unwrap_or(0)     }      fn draw_into(&amp;self, buffer: &amp;mut dyn std::fmt::Write) {         writeln!(buffer, \"{}\", &amp;self.label).unwrap();     } }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ src\/widgets\/button.rs use super::{Label, Widget};  pub struct Button {     label: Label, }  impl Button {     pub fn new(label: &amp;str) -> Button {         Button { label: Label::new(label) }     } }  impl Widget for Button {     fn width(&amp;self) -> usize {         self.label.width() + 4     }      fn draw_into(&amp;self, buffer: &amp;mut dyn std::fmt::Write) {         let width = self.width();         let mut label = String::new();         self.label.draw_into(&amp;mut label);          writeln!(buffer, \"+{:-&lt;width$}+\", \"\").unwrap();         for line in label.lines() {             writeln!(buffer, \"|{:^width$}|\", &amp;line).unwrap();         }         writeln!(buffer, \"+{:-&lt;width$}+\", \"\").unwrap();     } }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ src\/widgets\/window.rs use super::Widget;  pub struct Window {     title: String,     widgets: Vec&lt;Box&lt;dyn Widget>>, }  impl Window {     pub fn new(title: &amp;str) -> Window {         Window { title: title.to_owned(), widgets: Vec::new() }     }      pub fn add_widget(&amp;mut self, widget: Box&lt;dyn Widget>) {         self.widgets.push(widget);     }      fn inner_width(&amp;self) -> usize {         std::cmp::max(             self.title.chars().count(),             self.widgets.iter().map(|w| w.width()).max().unwrap_or(0),         )     } }  impl Widget for Window {     fn width(&amp;self) -> usize {         self.inner_width() + 4     }      fn draw_into(&amp;self, buffer: &amp;mut dyn std::fmt::Write) {         let mut inner = String::new();         for widget in &amp;self.widgets {             widget.draw_into(&amp;mut inner);         }          let inner_width = self.inner_width();          writeln!(buffer, \"+-{:-&lt;inner_width$}-+\", \"\").unwrap();         writeln!(buffer, \"| {:^inner_width$} |\", &amp;self.title).unwrap();         writeln!(buffer, \"+={:=&lt;inner_width$}=+\", \"\").unwrap();         for line in inner.lines() {             writeln!(buffer, \"| {:inner_width$} |\", line).unwrap();         }         writeln!(buffer, \"+-{:-&lt;inner_width$}-+\", \"\").unwrap();     } }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ src\/main.rs mod widgets;  use widgets::Widget;  fn main() {     let mut window = widgets::Window::new(\"Rust GUI Demo 1.23\");     window         .add_widget(Box::new(widgets::Label::new(\"This is a small text GUI demo.\")));     window.add_widget(Box::new(widgets::Button::new(\"Click me!\")));     window.draw(); }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h2 id=\"testirovanie\">\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p><strong>\u041c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0435\/\u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u044b<\/strong><\/p>\n<p>  <\/p>\n<p><code>Rust<\/code> \u0438 <code>Cargo<\/code> \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0435 (unit) \u0442\u0435\u0441\u0442\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u0434\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0438\u0448\u0435\u043c<\/li>\n<li>\u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 (integration) \u0442\u0435\u0441\u0442\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>tests<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0422\u0435\u0441\u0442\u044b \u043f\u043e\u043c\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b <code>#[test]<\/code>. \u042e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u044b \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c <code>tests<\/code>. \u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 <code>#[cfg(test)]<\/code> \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443, \u0447\u0442\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439\u0441\u044f \u0434\u0430\u043b\u0435\u0435 \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn first_word(text: &amp;str) -> &amp;str {     match text.find(' ') {         Some(idx) => &amp;text[..idx],         None => &amp;text,     } }  #[cfg(test)] mod test {     use super::*;      #[test]     fn test_empty() {         assert_eq!(first_word(\"\"), \"\");     }      #[test]     fn test_single_word() {         assert_eq!(first_word(\"Hello\"), \"Hello\");     }      #[test]     fn test_multiple_words() {         assert_eq!(first_word(\"Hello World\"), \"Hello\");     } }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u041c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b<\/li>\n<li>\u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>#[cfg(test)]<\/code> \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 <code>cargo test<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u0414\u0440\u0443\u0433\u0438\u0435 \u0442\u0438\u043f\u044b \u0442\u0435\u0441\u0442\u043e\u0432<\/strong><\/p>\n<p>  <\/p>\n<p><em>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b<\/em><\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043e\u0442 \u043b\u0438\u0446\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <code>.rs<\/code> \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>tests\/<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/ tests\/my_library.rs use my_library::init;  #[test] fn test_init() {     assert!(init().is_ok()); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u0438 \u0442\u0435\u0441\u0442\u044b \u0438\u043c\u0435\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u043c\u0443 API \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u0440\u0435\u0439\u0442\u0430.<\/p>\n<p>  <\/p>\n<p><em>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b<\/em><\/p>\n<p>  <\/p>\n<p><code>Rust<\/code> \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/\/ \u0421\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b. \/\/\/ \/\/\/ ``` \/\/\/ # use playground::shorten_string; \/\/\/ assert_eq!(shorten_string(\"Hello World\", 5), \"Hello\"); \/\/\/ assert_eq!(shorten_string(\"Hello World\", 20), \"Hello World\"); \/\/\/ ``` pub fn shorten_string(s: &amp;str, length: usize) -> &amp;str {     &amp;s[..std::cmp::min(length, s.len())] } <\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u0411\u043b\u043e\u043a\u0438 \u043a\u043e\u0434\u0430 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 <code>\/\/\/<\/code> \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c <code>Rust<\/code> (\u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043a\u043e\u0434 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f)<\/li>\n<li>\u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c <code>cargo test<\/code><\/li>\n<li>\u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <code>#<\/code> \u0432 \u043a\u043e\u0434 \u0441\u043a\u0440\u043e\u0435\u0442 \u0435\u0433\u043e \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043d\u043e \u043e\u043d \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f\/\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043a\u0440\u0435\u0439\u0442\u044b<\/strong><\/p>\n<p>  <\/p>\n<p><code>Rust<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043b\u0438\u0448\u044c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0442\u0435\u0441\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0440\u0435\u0439\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/docs.rs\/googletest\">googletest<\/a> \u2014 \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043b\u0443\u0447\u0448\u0438\u0445 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u044f\u0445 <code>GoogleTest<\/code> \u0434\u043b\u044f <code>C++<\/code><\/li>\n<li><a href=\"https:\/\/docs.rs\/proptest\">proptest<\/a> \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 (properties)<\/li>\n<li><a href=\"https:\/\/docs.rs\/rstest\">rstest<\/a> \u2014 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0430\u044f \u0444\u0438\u043a\u0441\u0442\u0443\u0440\u044b (fixtures) \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u0441\u0442\u044b<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>GoogleTest<\/strong><\/p>\n<p>  <\/p>\n<p>\u041a\u0440\u0435\u0439\u0442 <a href=\"https:\/\/docs.rs\/googletest\">googletest<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0433\u0438\u0431\u043a\u0438\u0435 \u0442\u0435\u0441\u0442\u044b \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u0435\u043b\u0435\u0439 (matchers):<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use googletest::prelude::*;  #[googletest::test] fn test_elements_are() {     let value = vec![\"foo\", \"bar\", \"baz\"];     expect_that!(value, elements_are!(eq(\"foo\"), lt(\"xyz\"), starts_with(\"b\"))); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043c <code>b<\/code> \u043d\u0430 <code>!<\/code> \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435, \u0442\u0435\u0441\u0442 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u0441\u044f \u0441 \u0432\u044b\u0434\u0430\u0447\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">---- test_elements_are stdout ---- Value of: value Expected: has elements:   0. is equal to \"foo\"   1. is less than \"xyz\"   2. starts with prefix \"!\" Actual: [\"foo\", \"bar\", \"baz\"],   where element #2 is \"baz\", which does not start with \"!\"   at src\/testing\/googletest.rs:6:5 Error: See failure output above<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u043c\u0430\u0440\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 <code>cargo add googletest<\/code> \u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 <code>googletest<\/code><\/li>\n<li><code>use googletest::prelude::*;<\/code> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 <a href=\"https:\/\/docs.rs\/googletest\/latest\/googletest\/prelude\/index.html\">\u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043c\u0430\u043a\u0440\u043e\u0441\u044b \u0438 \u0442\u0438\u043f\u044b<\/a><\/li>\n<li><code>googletest<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u0435\u043b\u0435\u0439<\/li>\n<li>\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e <code>googletest<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f \u0432 \u043c\u043d\u043e\u0433\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0440\u0430\u0437\u043d\u0438\u0446\u044b:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn test_multiline_string_diff() {     let haiku = \"Memory safety found,\\n\\                  Rust's strong typing guides the way,\\n\\                  Secure code you'll write.\";     assert_that!(         haiku,         eq(\"Memory safety found,\\n\\             Rust's silly humor guides the way,\\n\\             Secure code you'll write.\")     ); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0432\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0446\u0432\u0435\u0442\u043d\u044b\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">    Value of: haiku Expected: is equal to \"Memory safety found,\\nRust's silly humor guides the way,\\nSecure code you'll write.\" Actual: \"Memory safety found,\\nRust's strong typing guides the way,\\nSecure code you'll write.\",   which isn't equal to \"Memory safety found,\\nRust's silly humor guides the way,\\nSecure code you'll write.\" Difference(-actual \/ +expected):  Memory safety found, -Rust's strong typing guides the way, +Rust's silly humor guides the way,  Secure code you'll write.   at src\/testing\/googletest.rs:17:5=<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u041c\u043e\u043a\u0438\u043d\u0433<\/strong><\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043c\u043e\u043a\u0438\u043d\u0433\u0430 (mocking \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u0430\u043a\u0435\u0442\u0430) \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/docs.rs\/mockall\/\">mockall<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use std::time::Duration;  #[mockall::automock] pub trait Pet {     fn is_hungry(&amp;self, since_last_meal: Duration) -> bool; }  #[test] fn test_robot_dog() {     let mut mock_dog = MockPet::new();     mock_dog.expect_is_hungry().return_const(true);     assert_eq!(mock_dog.is_hungry(Duration::from_secs(10)), true); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u043c\u0430\u0440\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0434\u043b\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 <code>mockall<\/code> \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>cargo add mockall<\/code><\/li>\n<li>\u043d\u0430 <a href=\"https:\/\/crates.io\/keywords\/mock\">crates.io \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u043c\u043e\u043a\u0438\u043d\u0433\u0430<\/a>, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0434\u043b\u044f \u043c\u043e\u043a\u0438\u043d\u0433\u0430 HTTP-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432. \u0414\u0440\u0443\u0433\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e <code>Mockall<\/code>: \u043e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u0430\u043a\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0440\u0435\u0439\u0442\u0430<\/li>\n<li>\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0430\u043a\u0435\u0442\u043e\u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0432\u043e: \u043c\u0430\u043a\u0435\u0442\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0441\u0442 \u043e\u0442 \u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u041d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043c\u0430\u043a\u0435\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u0438 \u0431\u044b \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u041f\u043e-\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043d\u043e\u0433\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 (in-memory backend). \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432, \u043f\u043b\u044e\u0441 \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0447\u0438\u0449\u0430\u044e\u0442\u0441\u044f. \u041c\u043d\u043e\u0433\u0438\u0435 \u0432\u0435\u0431-\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u0440\u0442\u0443 \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u0445\u043e\u0441\u0442\u0435. \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u0447\u0435\u043c \u043c\u043e\u043a\u0438\u043d\u0433, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435<\/li>\n<li><code>Mockall<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f (expectations), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0430\u043a\u0435\u0442 \u043a\u043e\u0448\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0433\u043e\u043b\u043e\u0434\u0430\u043b\u0430\u0441\u044c \u0447\u0435\u0440\u0435\u0437 3 \u0447\u0430\u0441\u0430 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0435\u0435 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u0430\u0437 \u043f\u043e\u043a\u043e\u0440\u043c\u0438\u043b\u0438:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"rust\">#[test] fn test_robot_cat() {     let mut mock_cat = MockPet::new();     mock_cat         .expect_is_hungry()         .with(mockall::predicate::gt(Duration::from_secs(3 * 3600)))         .return_const(true);     mock_cat.expect_is_hungry().return_const(false);     assert_eq!(mock_cat.is_hungry(Duration::from_secs(1 * 3600)), false);     assert_eq!(mock_cat.is_hungry(Duration::from_secs(5 * 3600)), true); }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>.times(n)<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043e <code>n<\/code> \u2014 \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043b\u0438\u043c\u0438\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0437\u0430\u043f\u0430\u043d\u0438\u043a\u0443\u0435\u0442<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041b\u0438\u043d\u0442\u0435\u0440 \u0438 Clippy<\/strong><\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 <code>Rust<\/code> \u0432\u044b\u0434\u0430\u0435\u0442 \u0444\u0430\u043d\u0442\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 (lints). <a href=\"https:\/\/doc.rust-lang.org\/clippy\/\">Clippy<\/a> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043e\u043a, \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u0433\u0440\u0443\u043f\u043f\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c\/\u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[deny(clippy::cast_possible_truncation)] fn main() {     let x = 3;     while (x &lt; 70000) {         x *= 2;     }     println!(\"X \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 u16, \u0432\u0435\u0440\u043d\u043e? {}\", x as u16); }<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435: \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041b\u0443\u043d\u0430<\/strong><\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Luhn_algorithm\">\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041b\u0443\u043d\u0430<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u043e\u043c\u0435\u0440\u043e\u0432 \u043a\u0440\u0435\u0434\u0438\u0442\u043d\u044b\u0445 \u043a\u0430\u0440\u0442. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u044b<\/li>\n<li>\u043e\u0442\u043a\u043b\u043e\u043d\u044f\u0435\u043c \u043d\u043e\u043c\u0435\u0440\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u043c\u0435\u043d\u0435\u0435 \u0434\u0432\u0443\u0445 \u0446\u0438\u0444\u0440<\/li>\n<li>\u0434\u0432\u0438\u0433\u0430\u044f\u0441\u044c \u0441\u043f\u0440\u0430\u0432\u0430 \u043d\u0430\u043b\u0435\u0432\u043e, \u0443\u0434\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0432\u0442\u043e\u0440\u0443\u044e \u0446\u0438\u0444\u0440\u0443: \u0434\u043b\u044f \u0447\u0438\u0441\u043b\u0430 1234 \u0443\u0434\u0432\u0430\u0438\u0432\u0430\u0435\u043c 3 \u0438 1, \u0434\u043b\u044f \u0447\u0438\u0441\u043b\u0430 98765 \u0443\u0434\u0432\u0430\u0438\u0432\u0430\u0435\u043c 6 \u0438 8<\/li>\n<li>\u043f\u043e\u0441\u043b\u0435 \u0443\u0434\u0432\u043e\u0435\u043d\u0438\u044f \u0446\u0438\u0444\u0440\u044b \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0446\u0438\u0444\u0440\u044b, \u0435\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 9. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0443\u0434\u0432\u043e\u0435\u043d\u0438\u0435 7 \u0434\u0430\u0435\u0442 14, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 1 + 4 = 5<\/li>\n<li>\u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u0443\u0434\u0432\u043e\u0435\u043d\u043d\u044b\u0435 \u0438 \u0443\u0434\u0432\u043e\u0435\u043d\u043d\u044b\u0435 \u0446\u0438\u0444\u0440\u044b<\/li>\n<li>\u043d\u043e\u043c\u0435\u0440 \u043a\u0440\u0435\u0434\u0438\u0442\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d, \u0435\u0441\u043b\u0438 \u0441\u0443\u043c\u043c\u0430 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 0<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u041b\u0443\u043d\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0432\u0430 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">pub fn luhn(cc_number: &amp;str) -> bool {     let mut sum = 0;     let mut double = false;      for c in cc_number.chars().rev() {         if let Some(digit) = c.to_digit(10) {             if double {                 let double_digit = digit * 2;                 sum +=                     if double_digit > 9 { double_digit - 9 } else { double_digit };             } else {                 sum += digit;             }             double = !double;         } else {             continue;         }     }      sum % 10 == 0 }  fn main() {     let cc_number = \"1234 5678 1234 5670\";     println!(         \"{cc_number} \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u043a\u0440\u0435\u0434\u0438\u0442\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u044b? {}\",         if luhn(cc_number) { \"\u0414\u0430\" } else { \"\u041d\u0435\u0442\" }     ); }  #[cfg(test)] mod test {     use super::*;      #[test]     fn test_valid_cc_number() {         assert!(luhn(\"4263 9826 4026 9299\"));         assert!(luhn(\"4539 3195 0343 6467\"));         assert!(luhn(\"7992 7398 713\"));     }      #[test]     fn test_invalid_cc_number() {         assert!(!luhn(\"4223 9826 4026 9299\"));         assert!(!luhn(\"4539 3195 0343 6476\"));         assert!(!luhn(\"8273 1232 7352 0569\"));     }      #[test]     fn test_non_digit_cc_number() {         assert!(!luhn(\"foo\"));         assert!(!luhn(\"foo 0 0\"));     }      #[test]     fn test_empty_cc_number() {         assert!(!luhn(\"\"));         assert!(!luhn(\" \"));         assert!(!luhn(\"  \"));         assert!(!luhn(\"    \"));     }      #[test]     fn test_single_digit_cc_number() {         assert!(!luhn(\"0\"));     }      #[test]     fn test_two_digit_cc_number() {         assert!(luhn(\" 0 0 \"));     } }<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"rust\">pub fn luhn(cc_number: &amp;str) -> bool {     \/\/ \u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0441\u0443\u043c\u043c\u0430 \u0446\u0438\u0444\u0440     let mut sum = 0;     \/\/ \u0418\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0443\u0434\u0432\u043e\u0435\u043d\u0438\u044f \u0446\u0438\u0444\u0440\u044b     let mut double = false;     \/\/ \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0438\u0444\u0440     let mut digits = 0;      \/\/ \u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0446\u0438\u0444\u0440\u044b \u0441\u043f\u0440\u0430\u0432\u0430 \u043d\u0430\u043b\u0435\u0432\u043e     for c in cc_number.chars().rev() {         \/\/ \u0415\u0441\u043b\u0438 \u0441\u0438\u043c\u0432\u043e\u043b \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c \u0434\u0435\u0441\u044f\u0442\u0438\u0447\u043d\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c         if let Some(digit) = c.to_digit(10) {             \/\/ \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0438\u0444\u0440             digits += 1;             \/\/ \u0415\u0441\u043b\u0438 \u0446\u0438\u0444\u0440\u0443 \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0432\u043e\u0438\u0442\u044c             if double {                 let double_digit = digit * 2;                 \/\/ \u0415\u0441\u043b\u0438 \u0443\u0434\u0432\u043e\u0435\u043d\u043d\u0430\u044f \u0446\u0438\u0444\u0440\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 9, \u0432\u044b\u0447\u0438\u0442\u0430\u0435\u043c \u0438\u0437 \u043d\u0435\u0435 9:                 \/\/ \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 14, \u0442\u043e 1 + 4 = 5, \u0447\u0442\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e 14 - 9 = 5                 sum +=                     if double_digit > 9 { double_digit - 9 } else { double_digit };             \/\/ \u0418\u043d\u0430\u0447\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0446\u0438\u0444\u0440\u0443 \u043a \u0441\u0443\u043c\u043c\u0435             } else {                 sum += digit;             }             \/\/ \u0423\u0434\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0432\u0442\u043e\u0440\u0443\u044e \u0446\u0438\u0444\u0440\u0443             double = !double;         \/\/ \u0418\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0431\u0435\u043b\u044b         } else if c.is_whitespace() {             continue;         \/\/ \u0415\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0438\u043c\u0432\u043e\u043b, \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u043e\u0442 \u0446\u0438\u0444\u0440\u044b \u0438 \u043f\u0440\u043e\u0431\u0435\u043b\u0430         } else {             return false;         }     }      \/\/ \u0426\u0438\u0444\u0440 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0432\u0443\u0445 \u0438 \u0441\u0443\u043c\u043c\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 0     digits >= 2 &amp;&amp; sum % 10 == 0 }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h2 id=\"obrabotka-oshibok\">\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/h2>\n<p>  <\/p>\n<p><strong>\u041f\u0430\u043d\u0438\u043a\u0430<\/strong><\/p>\n<p>  <\/p>\n<p>\u0424\u0430\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 <code>Rust<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e &#171;\u043f\u0430\u043d\u0438\u043a\u0438&#187; (panic).<\/p>\n<p>  <\/p>\n<p>\u041f\u0430\u043d\u0438\u043a\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0444\u0430\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn main() {     let v = vec![10, 20, 30];     println!(\"v[100]: {}\", v[100]); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u043c\u0430\u0440\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043f\u0430\u043d\u0438\u043a\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0441 \u043d\u0435\u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043c\u044b\u043c\u0438 \u0438 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438:<br \/> \n<ul>\n<li>\u043f\u0430\u043d\u0438\u043a\u0430 \u2014 \u044d\u0442\u043e \u0441\u0438\u043c\u043f\u0442\u043e\u043c\u044b \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435<\/li>\n<li>\u0441\u0431\u043e\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0433\u0440\u0430\u043d\u0438\u0446 (boundaries), \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u0430\u043d\u0438\u043a\u0443<\/li>\n<li>\u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>assert!<\/code>) \u043f\u0430\u043d\u0438\u043a\u0443\u044e\u0442 \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u0435<\/li>\n<li>\u0434\u043b\u044f \u0446\u0435\u043b\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043d\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043a\u0440\u043e\u0441 <code>panic!<\/code><\/li>\n<\/ul>\n<\/li>\n<li>\u043f\u0430\u043d\u0438\u043a\u0430 &#171;\u0440\u0430\u0437\u043c\u0430\u0442\u044b\u0432\u0430\u0435\u0442&#187; (unwind) \u0441\u0442\u0435\u043a, \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0435\u0440\u043d\u0443\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/li>\n<li>\u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Vec::get<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u0430\u043d\u0438\u043a\u0430 \u0440\u0430\u0437\u043c\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0442\u0435\u043a. \u0420\u0430\u0437\u043c\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use std::panic;  fn main() {     let result = panic::catch_unwind(|| \"No problem here!\");     println!(\"{result:?}\");      let result = panic::catch_unwind(|| {         panic!(\"Oh no!\");     });     println!(\"{result:?}\"); }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u041d\u0435 \u043f\u044b\u0442\u0430\u0439\u0442\u0435\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>catch_unwind<\/code><\/li>\n<li>\u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0431\u043e\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/li>\n<li>\u044d\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 <code>panic = 'abort'<\/code> \u0432 <code>Cargo.toml<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 ?<\/strong><\/p>\n<p>  <\/p>\n<p>\u041e\u0448\u0438\u0431\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043e\u0442\u043a\u0430\u0437 \u0432 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u0438\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0444\u0430\u0439\u043b\u0430, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0438\u043f\u0430 <code>Result<\/code>, \u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 (matching) \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0442\u043e\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u0438\u0437\u043b\u0438\u0448\u043d\u0438\u043c. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>?<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u043c\u0443 (caller). \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">match some_expression {     Ok(value) => value,     Err(err) => return Err(err), }<\/code><\/pre>\n<p>  <\/p>\n<p>\u043d\u0430<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">some_expression?<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043a\u043e\u0434\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use std::io::Read; use std::{fs, io};  fn read_username(path: &amp;str) -> Result&lt;String, io::Error> {     let username_file_result = fs::File::open(path);     let mut username_file = match username_file_result {         Ok(file) => file,         Err(err) => return Err(err),     };      let mut username = String::new();     match username_file.read_to_string(&amp;mut username) {         Ok(_) => Ok(username),         Err(err) => Err(err),     } }  fn main() {     \/\/ fs::write(\"config.dat\", \"alice\").unwrap();     let username = read_username(\"config.dat\");     println!(\"username or error: {username:?}\"); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>username<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0431\u043e <code>Ok(String)<\/code>, \u043b\u0438\u0431\u043e <code>Err(error)<\/code><\/li>\n<li>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>fs::write<\/code> \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432: \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0444\u0430\u0439\u043b\u0430, \u043f\u0443\u0441\u0442\u043e\u0439 \u0444\u0430\u0439\u043b, \u0444\u0430\u0439\u043b \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/li>\n<li>\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <code>main<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <code>Result&lt;(), E><\/code> \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>std::process:Termination<\/code>. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e <code>E<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>Debug<\/code>. \u0418\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u0444\u0430\u0439\u043b \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 <code>Err<\/code> \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u0443\u0441 \u0432\u044b\u0445\u043e\u0434\u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f Try<\/strong><\/p>\n<p>  <\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>?<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0447\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">expression?<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u044d\u0442\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">match expression {     Ok(value) => value,     Err(err)  => return Err(From::from(err)), }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0437\u043e\u0432 <code>From::from<\/code> \u0437\u0434\u0435\u0441\u044c \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0442\u0438\u043f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f.<\/p>\n<p>  <\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0440<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use std::error::Error; use std::fmt::{self, Display, Formatter}; use std::fs::File; use std::io::{self, Read};  #[derive(Debug)] enum ReadUsernameError {     IoError(io::Error),     EmptyUsername(String), }  impl Error for ReadUsernameError {}  impl Display for ReadUsernameError {     fn fmt(&amp;self, f: &amp;mut Formatter) -> fmt::Result {         match self {             Self::IoError(e) => write!(f, \"\u041e\u0448\u0438\u0431\u043a\u0430 \u0432\u0432\u043e\u0434\u0430\/\u0432\u044b\u0432\u043e\u0434\u0430: {e}\"),             Self::EmptyUsername(path) => write!(f, \"\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 {path}\"),         }     } }  impl From&lt;io::Error> for ReadUsernameError {     fn from(err: io::Error) -> Self {         Self::IoError(err)     } }  fn read_username(path: &amp;str) -> Result&lt;String, ReadUsernameError> {     let mut username = String::with_capacity(100);     File::open(path)?.read_to_string(&amp;mut username)?;     if username.is_empty() {         return Err(ReadUsernameError::EmptyUsername(String::from(path)));     }     Ok(username) }  fn main() {     \/\/ fs::write(\"config.dat\", \"\").unwrap();     let username = read_username(\"config.dat\");     println!(\"\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430: {username:?}\"); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>?<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0435 \u0441 \u0442\u0438\u043f\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439. \u0414\u043b\u044f <code>Result<\/code> \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0442\u0438\u043f\u044b \u043e\u0448\u0438\u0431\u043e\u043a \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c\u0438. \u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f <code>Result&lt;T, ErrorOuter><\/code>, \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>?<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>Result&lt;U, ErrorInner><\/code>, \u0435\u0441\u043b\u0438 <code>ErrorOuter<\/code> \u0438 <code>ErrorInner<\/code> \u0438\u043c\u0435\u044e\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0442\u0438\u043f, \u0438\u043b\u0438 \u0435\u0441\u043b\u0438 <code>ErrorOuter<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>From&lt;ErrorInner><\/code>.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u043e\u0439 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>From<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>Result::map_err<\/code>, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f <code>Option<\/code> \u043d\u0435\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438. \u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f <code>Option&lt;T><\/code>, \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>?<\/code> \u043d\u0430 <code>Option&lt;U><\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 <code>T<\/code> \u0438 <code>U<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0430\u044f <code>Result<\/code>, \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>?<\/code> \u043d\u0430 <code>Option<\/code>, \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u041e\u0434\u043d\u0430\u043a\u043e, <code>Option::ok_or<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 <code>Option<\/code> \u0432 <code>Result<\/code>, \u0430 <code>Result::ok<\/code> \u2014 <code>Result<\/code> \u0432 <code>Option<\/code>.<\/p>\n<p>  <\/p>\n<p><strong>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u043e\u0448\u0438\u0431\u043e\u043a<\/strong><\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u043e\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u0432\u0441\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b. \u0422\u0440\u0435\u0439\u0442 <code>std::error::Error<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0440\u0435\u0439\u0442-\u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use std::error::Error; use std::fs; use std::io::Read;  fn read_count(path: &amp;str) -> Result&lt;i32, Box&lt;dyn Error>> {     let mut count_str = String::new();     fs::File::open(path)?.read_to_string(&amp;mut count_str)?;     let count: i32 = count_str.parse()?;     Ok(count) }  fn main() {     fs::write(\"count.dat\", \"1i3\").unwrap();     match read_count(\"count.dat\") {         Ok(count) => println!(\"\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435: {count}\"),         Err(err) => println!(\"\u041e\u0448\u0438\u0431\u043a\u0430: {err}\"),     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>read_count<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c <code>std::io::Error<\/code> (\u0438\u0437 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 \u0444\u0430\u0439\u043b\u043e\u043c) \u0438\u043b\u0438 <code>std::num::ParseIntError<\/code> (\u0438\u0437 <code>String::parse<\/code>).<\/p>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 (boxing) \u043e\u0448\u0438\u0431\u043e\u043a \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430, \u043d\u043e \u043b\u0438\u0448\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Box&lt;dyn Error><\/code> \u0432 \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u043c API \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f, \u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u0433\u0434\u0435-\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043e\u0448\u0438\u0431\u043e\u043a \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u043e\u043d\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 <code>std::error::Error<\/code>, \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u0432 <code>Box<\/code>.<\/p>\n<p>  <\/p>\n<p><strong>thiserror \u0438 anyhow<\/strong><\/p>\n<p>  <\/p>\n<p>\u041a\u0440\u0435\u0439\u0442\u044b <a href=\"https:\/\/docs.rs\/thiserror\/\">thiserror<\/a> \u0438 <a href=\"https:\/\/docs.rs\/anyhow\/\">anyhow<\/a> \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a. <code>thiserror<\/code> \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043e\u0448\u0438\u0431\u043e\u043a, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0435 <code>From&lt;T><\/code>. <code>anyhow<\/code> \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use anyhow::{bail, Context, Result}; use std::fs; use std::io::Read; use thiserror::Error;  #[derive(Clone, Debug, Eq, Error, PartialEq)] #[error(\"\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 {0}\")] struct EmptyUsernameError(String);  fn read_username(path: &amp;str) -> Result&lt;String> {     let mut username = String::with_capacity(100);     fs::File::open(path)         .with_context(|| format!(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 {path}\"))?         .read_to_string(&amp;mut username)         .context(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438\")?;     if username.is_empty() {         bail!(EmptyUsernameError(path.to_string()));     }     Ok(username) }  fn main() {     \/\/ fs::write(\"config.dat\", \"\").unwrap();     match read_username(\"config.dat\") {         Ok(username) => println!(\"\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f: {username}\"),         Err(err) => println!(\"\u041e\u0448\u0438\u0431\u043a\u0430: {err:?}\"),     } }<\/code><\/pre>\n<p>  <\/p>\n<p><code>thiserror<\/code>:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043c\u0430\u043a\u0440\u043e\u0441 <code>error<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>thiserror<\/code> \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0434\u043b\u044f \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u043e\u0448\u0438\u0431\u043e\u043a<\/li>\n<li>\u0442\u0440\u0435\u0439\u0442 <code>std::error::Error<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438<\/li>\n<li>\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438\u0437 <code>#[error]<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0435\u0439\u0442\u0430 <code>Display<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p><code>anyhow<\/code>:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>anyhow::Error<\/code> \u2014 \u044d\u0442\u043e \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 <code>Box&lt;dyn Error><\/code>. \u041e\u043f\u044f\u0442\u044c \u0436\u0435 \u044d\u0442\u043e \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u0439 \u0432\u044b\u0431\u043e\u0440 \u0434\u043b\u044f \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e API \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043d\u043e \u043e\u043d \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445<\/li>\n<li><code>anyhow::Result&lt;V><\/code> \u2014 \u044d\u0442\u043e \u0441\u0438\u043d\u043e\u043d\u0438\u043c \u0442\u0438\u043f\u0430 <code>Result&lt;V, anyhow::Error><\/code><\/li>\n<li>\u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438<\/li>\n<li><code>anyhow::Context<\/code> \u2014 \u044d\u0442\u043e \u0442\u0440\u0435\u0439\u0442, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 <code>Result<\/code> \u0438 <code>Option<\/code>. <code>use anyhow::Context<\/code> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <code>.context()<\/code> \u0438 <code>.with_context()<\/code> \u043d\u0430 \u044d\u0442\u0438\u0445 \u0442\u0438\u043f\u0430\u0445<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435: \u0431\u0435\u0437 \u043f\u0430\u043d\u0438\u043a\u0438<\/strong><\/p>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u044f\u0437\u044b\u043a\u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u043e\u043d \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0443\u0442\u0435\u043c \u043f\u0430\u043d\u0438\u043a\u0438. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0438\u0442\u0435 \u0435\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0434\u0438\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0438\u0437 <code>main<\/code>. \u041d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>thiserror<\/code> \u0438 <code>anyhow<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0430: \u043d\u0430\u0447\u043d\u0438\u0442\u0435 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>parse<\/code>. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d\u0430 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u0435 <code>Tokenizer<\/code> \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>Iterator&lt;Item=Result&lt;Token, TokenizerError>><\/code> \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0439\u0442\u0435 \u0435\u0433\u043e \u0432 \u043f\u0430\u0440\u0441\u0435\u0440\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use std::iter::Peekable; use std::str::Chars;  \/\/ \u0410\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 #[derive(Debug, PartialEq, Clone, Copy)] enum Op {     Add,     Sub, }  \/\/ \u0422\u043e\u043a\u0435\u043d \u044f\u0437\u044b\u043a\u0430 #[derive(Debug, PartialEq)] enum Token {     Number(String),     Identifier(String),     Operator(Op), }  \/\/ \u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u044f\u0437\u044b\u043a\u0430 #[derive(Debug, PartialEq)] enum Expression {     \/\/ \u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e     Var(String),     \/\/ \u041b\u0438\u0442\u0435\u0440\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e     Number(u32),     \/\/ \u0411\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f     Operation(Box&lt;Expression>, Op, Box&lt;Expression>), }  fn tokenize(input: &amp;str) -> Tokenizer {     return Tokenizer(input.chars().peekable()); }  struct Tokenizer&lt;'a>(Peekable&lt;Chars&lt;'a>>);  impl&lt;'a> Iterator for Tokenizer&lt;'a> {     type Item = Token;      fn next(&amp;mut self) -> Option&lt;Token> {         let c = self.0.next()?;         match c {             '0'..='9' => {                 let mut num = String::from(c);                 while let Some(c @ '0'..='9') = self.0.peek() {                     num.push(*c);                     self.0.next();                 }                 Some(Token::Number(num))             }             'a'..='z' => {                 let mut ident = String::from(c);                 while let Some(c @ ('a'..='z' | '_' | '0'..='9')) = self.0.peek() {                     ident.push(*c);                     self.0.next();                 }                 Some(Token::Identifier(ident))             }             '+' => Some(Token::Operator(Op::Add)),             '-' => Some(Token::Operator(Op::Sub)),             _ => panic!(\"\u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b {c}\"),         }     } }  fn parse(input: &amp;str) -> Expression {     let mut tokens = tokenize(input);      fn parse_expr&lt;'a>(tokens: &amp;mut Tokenizer&lt;'a>) -> Expression {         let Some(tok) = tokens.next() else {             panic!(\"\u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0435\u0446 \u0432\u0432\u043e\u0434\u0430\");         };         let expr = match tok {             Token::Number(num) => {                 let v = num.parse().expect(\"\u041d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0435 32-\u0431\u0438\u0442\u043d\u043e\u0435 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e\");                 Expression::Number(v)             }             Token::Identifier(ident) => Expression::Var(ident),             Token::Operator(_) => panic!(\"\u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d {tok:?}\"),         };         \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438         match tokens.next() {             None => expr,             Some(Token::Operator(op)) => Expression::Operation(                 Box::new(expr),                 op,                 Box::new(parse_expr(tokens)),             ),             Some(tok) => panic!(\"\u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d {tok:?}\"),         }     }      parse_expr(&amp;mut tokens) }  fn main() {     let expr = parse(\"10+foo+20-30\");     println!(\"{expr:?}\"); }<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"rust\">use thiserror::Error; use std::iter::Peekable; use std::str::Chars;  #[derive(Debug, PartialEq, Clone, Copy)] enum Op {     Add,     Sub, }  #[derive(Debug, PartialEq)] enum Token {     Number(String),     Identifier(String),     Operator(Op), }  #[derive(Debug, PartialEq)] enum Expression {     Var(String),     Number(u32),     Operation(Box&lt;Expression>, Op, Box&lt;Expression>), }  fn tokenize(input: &amp;str) -> Tokenizer {     return Tokenizer(input.chars().peekable()); }  #[derive(Debug, Error)] enum TokenizerError {     #[error(\"\u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b {0}\")]     UnexpectedCharacter(char), }  struct Tokenizer&lt;'a>(Peekable&lt;Chars&lt;'a>>);  impl&lt;'a> Iterator for Tokenizer&lt;'a> {     type Item = Result&lt;Token, TokenizerError>;      fn next(&amp;mut self) -> Option&lt;Result&lt;Token, TokenizerError>> {         let c = self.0.next()?;         match c {             '0'..='9' => {                 let mut num = String::from(c);                 while let Some(c @ '0'..='9') = self.0.peek() {                     num.push(*c);                     self.0.next();                 }                 Some(Ok(Token::Number(num)))             }             'a'..='z' => {                 let mut ident = String::from(c);                 while let Some(c @ ('a'..='z' | '_' | '0'..='9')) = self.0.peek() {                     ident.push(*c);                     self.0.next();                 }                 Some(Ok(Token::Identifier(ident)))             }             '+' => Some(Ok(Token::Operator(Op::Add))),             '-' => Some(Ok(Token::Operator(Op::Sub))),             _ => Some(Err(TokenizerError::UnexpectedCharacter(c))),         }     } }  #[derive(Debug, Error)] enum ParserError {     #[error(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0442\u043e\u043a\u0435\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430: {0}\")]     TokenizerError(#[from] TokenizerError),     #[error(\"\u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0435\u0446 \u0432\u0432\u043e\u0434\u0430\")]     UnexpectedEOF,     #[error(\"\u041d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d {0:?}\")]     UnexpectedToken(Token),     #[error(\"\u041d\u0435\u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e\")]     InvalidNumber(#[from] std::num::ParseIntError), }  fn parse(input: &amp;str) -> Result&lt;Expression, ParserError> {     let mut tokens = tokenize(input);      fn parse_expr&lt;'a>(         tokens: &amp;mut Tokenizer&lt;'a>,     ) -> Result&lt;Expression, ParserError> {         let tok = tokens.next().ok_or(ParserError::UnexpectedEOF)??;         let expr = match tok {             Token::Number(num) => {                 let v = num.parse()?;                 Expression::Number(v)             }             Token::Identifier(ident) => Expression::Var(ident),             Token::Operator(_) => return Err(ParserError::UnexpectedToken(tok)),         };          Ok(match tokens.next() {             None => expr,             Some(Ok(Token::Operator(op))) => Expression::Operation(                 Box::new(expr),                 op,                 Box::new(parse_expr(tokens)?),             ),             Some(Err(e)) => return Err(e.into()),             Some(Ok(tok)) => return Err(ParserError::UnexpectedToken(tok)),         })     }      parse_expr(&amp;mut tokens) }  fn main() -> anyhow::Result&lt;()> {     let expr = parse(\"10+foo+20-30\")?;     println!(\"{expr:?}\");     Ok(()) }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h2 id=\"nebezopasnyy-rust\">\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 Rust<\/h2>\n<p>  <\/p>\n<p><strong>\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 Rust<\/strong><\/p>\n<p>  <\/p>\n<p><code>Rust<\/code> \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0447\u0430\u0441\u0442\u0435\u0439:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 <code>Rust<\/code> \u2014 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/li>\n<li>\u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 <code>Rust<\/code> \u2014 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e \u043f\u0440\u0438 \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u0443\u0440\u0441\u0435 \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 <code>Rust<\/code>, \u043d\u043e \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 <code>Rust<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439, \u0438 \u0435\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430. \u041e\u0431\u044b\u0447\u043d\u043e \u043e\u043d \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 (safe abstraction layer).<\/p>\n<p>  <\/p>\n<p>\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 <code>Rust<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a 5 \u043d\u043e\u0432\u044b\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u044b\u0440\u044b\u0445 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 (raw pointers)<\/li>\n<li>\u0434\u043e\u0441\u0442\u0443\u043f \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/li>\n<li>\u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u043b\u044f\u043c <code>union<\/code><\/li>\n<li>\u0432\u044b\u0437\u043e\u0432 <code>unsafe<\/code> \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0432\u043a\u043b\u044e\u0447\u0430\u044f <code>extern<\/code> (\u0432\u043d\u0435\u0448\u043d\u0438\u0435) \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/li>\n<li>\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>unsafe<\/code> \u0442\u0440\u0435\u0439\u0442\u043e\u0432<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 <code>Rust<\/code> \u043d\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u0434 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439. \u041e\u043d \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u0438 \u0438\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 <code>Rust<\/code>.<\/p>\n<p>  <\/p>\n<p><strong>\u0420\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u044b\u0440\u044b\u0445 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439<\/strong><\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c, \u043d\u043e \u0438\u0445 \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 <code>unsafe<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn main() {     let mut s = String::from(\"careful!\");      let r1 = &amp;mut s as *mut String;     let r2 = r1 as *const String;      \/\/ \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 r1 \u0438 r2 \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0438\u0437 \u0441\u0441\u044b\u043b\u043e\u043a \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443     \/\/ \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e \u043d\u0435 \u0440\u0430\u0432\u043d\u044b \u043d\u0443\u043b\u044e \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0440\u043e\u0432\u043d\u0435\u043d\u044b (properly aligned), \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043b\u0435\u0436\u0430\u0449\u0438\u0435 \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0441\u044b\u043b\u043e\u043a,     \/\/ \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b, \u0430\u043a\u0442\u0438\u0432\u043d\u044b \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430,     \/\/ \u0438 \u043a \u043d\u0438\u043c \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043d\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0441\u044b\u043b\u043a\u0438, \u043d\u0438 (\u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e) \u0447\u0435\u0440\u0435\u0437 \u0434\u0440\u0443\u0433\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438     unsafe {         println!(\"r1 is: {}\", *r1);         *r1 = String::from(\"uhoh\");         println!(\"r2 is: {}\", *r2);     }      \/\/ \u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e. \u041d\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0442\u0430\u043a     \/*     let r3: &amp;String = unsafe { &amp;*r1 };     drop(s);     println!(\"r3 is: {}\", *r3);     *\/ }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430, \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e\u0449\u0435\u0433\u043e, \u043a\u0430\u043a \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0433\u043e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0438\u043c \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <a href=\"https:\/\/doc.rust-lang.org\/std\/ptr\/index.html#safety\">\u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c\u0438<\/a>, \u0442.\u0435.:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0432\u043d\u044f\u0442\u044c\u0441\u044f \u043d\u0443\u043b\u044e<\/li>\n<li>\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u043c\u044b\u043c (\u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430)<\/li>\n<li>\u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d<\/li>\n<li>\u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438<\/li>\n<li>\u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0431\u044b\u043b \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u043f\u0443\u0442\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0438 (reference coercion), \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u0438 \u043d\u0438\u043a\u0430\u043a\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043c\u044f\u0442\u0438<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0440\u043e\u0432\u043d\u0435\u043d.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 &#171;\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e&#187; \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f: <code>*r1<\/code> \u0438\u043c\u0435\u0435\u0442 <code>'static<\/code> \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <code>r3<\/code> \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f <code>&amp;'static String<\/code> \u0438, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u0435\u0442 <code>s<\/code>. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442 <em>\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/em>.<\/p>\n<p>  <\/p>\n<p><strong>\u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/strong><\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">static HELLO_WORLD: &amp;str = \"Hello, world!\";  fn main() {     println!(\"HELLO_WORLD: {HELLO_WORLD}\"); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0440\u0438\u0441\u043a \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0433\u043e\u043d\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 (data race), \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">static mut COUNTER: u32 = 0;  fn add_to_counter(inc: u32) {     unsafe {         COUNTER += inc;     } }  fn main() {     add_to_counter(42);      unsafe {         println!(\"COUNTER: {COUNTER}\");     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u0430 \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u0430\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 <code>Rust<\/code> \u043a\u043e\u043d\u0441\u0435\u0440\u0432\u0430\u0442\u0438\u0432\u0435\u043d \u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u0445\u0443\u0434\u0448\u0435\u0435. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0443\u0434\u0430\u043b\u0438\u0442\u044c <code>unsafe<\/code> \u0438 \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u043a\u0438 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e.<\/p>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u043a\u0438, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043b\u043e\u0445\u043e\u0439 \u0438\u0434\u0435\u0435\u0439, \u043d\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0432 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u043c \u043a\u043e\u0434\u0435 <code>no_std<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f \u043a\u0443\u0447\u0438 (heap allocator) \u0438\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 API \u044f\u0437\u044b\u043a\u0430 <code>C<\/code>.<\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/strong><\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (unions) \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f, \u043d\u043e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[repr(C)] union MyUnion {     i: u8,     b: bool, }  fn main() {     let u = MyUnion { i: 42 };     println!(\"int: {}\", unsafe { u.i });     println!(\"bool: {}\", unsafe { u.b }); \/\/ \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 <code>Rust<\/code> \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u044b \u043e\u0447\u0435\u043d\u044c \u0440\u0435\u0434\u043a\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u0431\u044b\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0418\u043d\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 API \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u044f\u0437\u044b\u043a\u0430 <code>C<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0439\u0442\u044b \u043a\u0430\u043a \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0438\u043f, \u043d\u0430\u043c, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f <a href=\"https:\/\/doc.rust-lang.org\/stable\/std\/mem\/fn.transmute.html\">std::mem::transmute<\/a> \u0438\u043b\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0430\u044f \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0430, \u0442\u0430\u043a\u0430\u044f \u043a\u0430\u043a \u043a\u0440\u0435\u0439\u0442 <a href=\"https:\/\/crates.io\/crates\/zerocopy\">zerocopy<\/a>.<\/p>\n<p>  <\/p>\n<p><strong>\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/strong><\/p>\n<p>  <\/p>\n<p><em>\u0412\u044b\u0437\u043e\u0432 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/em><\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u043a\u0430\u043a <code>unsafe<\/code>, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0438\u0445 \u0435\u0441\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u044b \u0432\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u0435 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">extern \"C\" {     fn abs(input: i32) -> i32; }  fn main() {     let emojis = \"?\u2208?\";      \/\/ \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445     \/\/ \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 (string slice) \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 UTF-8     unsafe {         println!(\"\u044d\u043c\u043e\u0434\u0437\u0438: {}\", emojis.get_unchecked(0..4));         println!(\"\u044d\u043c\u043e\u0434\u0437\u0438: {}\", emojis.get_unchecked(4..7));         println!(\"\u044d\u043c\u043e\u0434\u0437\u0438: {}\", emojis.get_unchecked(7..11));     }      println!(\"\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432: {}\", count_chars(unsafe { emojis.get_unchecked(0..7) }));      unsafe {         \/\/ \u041f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435         println!(\"\u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 -3 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e C: {}\", abs(-3));     }      \/\/ \u041d\u0435\u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0438 UTF-8 \u043d\u0430\u0440\u0443\u0448\u0430\u0435\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438     \/\/ println!(\"\u044d\u043c\u043e\u0434\u0437\u0438: {}\", unsafe { emojis.get_unchecked(0..3) });     \/\/ println!(\"\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432: {}\", count_chars(unsafe {     \/\/ emojis.get_unchecked(0..3) })); }  fn count_chars(s: &amp;str) -> usize {     s.chars().count() }<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/em><\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u0430\u043a <code>unsafe<\/code>, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0432\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u0435 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">\/\/\/ \u041c\u0435\u043d\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \/\/\/ \/\/\/ # \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \/\/\/ \/\/\/ \u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c\u0438 \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0432\u044b\u0440\u043e\u0432\u043d\u0435\u043d\u043d\u044b\u043c\u0438 unsafe fn swap(a: *mut u8, b: *mut u8) {     let temp = *a;     *a = *b;     *b = temp; }  fn main() {     let mut a = 42;     let mut b = 66;      \/\/ \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443...     unsafe {         swap(&amp;mut a, &amp;mut b);     }      println!(\"a = {}, b = {}\", a, b); }<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u0412\u044b\u0437\u043e\u0432 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/em><\/p>\n<p>  <\/p>\n<p><code>get_unchecked<\/code>, \u043a\u0430\u043a \u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>_unchecked<\/code>, \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0430, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e, \u0435\u0441\u043b\u0438 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u043d\u0435\u0432\u0435\u0440\u0435\u043d. <code>abs<\/code> \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0430 \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435: \u044d\u0442\u043e \u0432\u043d\u0435\u0448\u043d\u044f\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (<code>FFI<\/code>). \u0412\u044b\u0437\u043e\u0432 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u0431\u044b\u0447\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0430\u043c\u044f\u0442\u0438 <code>Rust<\/code>, \u043d\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u043b\u044e\u0431\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>C<\/code> \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430\u0445.<\/p>\n<p>  <\/p>\n<p><em>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/em><\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u043d\u0435 \u0441\u0442\u0430\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u2014 \u0442\u0430\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0441\u044b\u043b\u043e\u043a.<\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0430 <code>unsafe<\/code>. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>#[deny(unsafe_op_in_unsafe_fn)]<\/code>. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u044d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 <code>Rust<\/code>.<\/p>\n<p>  <\/p>\n<p><strong>\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u0442\u0440\u0435\u0439\u0442\u044b<\/strong><\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u0442\u0440\u0435\u0439\u0442 \u043a\u0430\u043a <code>unsafe<\/code>, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u0435 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0440\u0435\u0439\u0442 <a href=\"https:\/\/docs.rs\/zerocopy\/latest\/zerocopy\/trait.AsBytes.html\">zerocopy<\/a> \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0442\u0440\u0435\u0439\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 <a href=\"https:\/\/docs.rs\/zerocopy\/latest\/zerocopy\/trait.AsBytes.html\">\u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">use std::mem::size_of_val; use std::slice;  \/\/\/ ... \/\/\/ # \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \/\/\/ \u0422\u0438\u043f \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043d\u0435 \u0438\u043c\u0435\u0442\u044c \u043e\u0442\u0441\u0442\u0443\u043f\u043e\u0432 (padding) pub unsafe trait AsBytes {     fn as_bytes(&amp;self) -> &amp;[u8] {         unsafe {             slice::from_raw_parts(                 self as *const Self as *const u8,                 size_of_val(self),             )         }     } }  \/\/ \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 `u32` \u0438\u043c\u0435\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u0441\u0442\u0443\u043f\u043e\u0432 unsafe impl AsBytes for u32 {}<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 <code>Rustdoc<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b <code># Safety<\/code> (\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c) \u0441 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c\u0438 \u043a \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0435\u0439\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f <code>AsBytes<\/code> \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0434\u043b\u0438\u043d\u043d\u0435\u0435 \u0438 \u0441\u043b\u043e\u0436\u043d\u0435\u0435.<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0442\u0440\u0435\u0439\u0442\u044b <code>Send<\/code> \u0438 <code>Sync<\/code> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c\u0438.<\/p>\n<p>  <\/p>\n<p><strong>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435: \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0430\u044f \u043e\u0431\u0435\u0440\u0442\u043a\u0430 FFI<\/strong><\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u044d\u0442\u043e \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u0438 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<p>\u0412 <code>Rust<\/code> \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 (foreign function interface, FFI). \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0438 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>libc<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 <code>C<\/code> \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u043d \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0435\u0437\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/opendir.3.html\">opendir(3)<\/a><\/li>\n<li><a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/readdir.3.html\">readdir(3)<\/a><\/li>\n<li><a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/closedir.3.html\">closedir(3)<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0443\u043b\u044f <a href=\"https:\/\/doc.rust-lang.org\/std\/ffi\/\">std::ffi<\/a>. \u0422\u0430\u043c \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0422\u0438\u043f\u044b<\/th>\n<th>\u041a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0430<\/th>\n<th>\u041d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/doc.rust-lang.org\/std\/primitive.str.html\">str<\/a> \u0438 <a href=\"https:\/\/doc.rust-lang.org\/std\/string\/struct.String.html\">String<\/a><\/td>\n<td>UTF-8<\/td>\n<td>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 <code>Rust<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/doc.rust-lang.org\/std\/ffi\/struct.CStr.html\">CStr<\/a> \u0438 <a href=\"https:\/\/doc.rust-lang.org\/std\/ffi\/struct.CString.html\">CString<\/a><\/td>\n<td>NUL-\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u0430\u044f<\/td>\n<td>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 <code>C<\/code><\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/doc.rust-lang.org\/std\/ffi\/struct.OsStr.html\">OsStr<\/a> \u0438 <a href=\"https:\/\/doc.rust-lang.org\/std\/ffi\/struct.OsString.html\">OsString<\/a><\/td>\n<td>\u0417\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u041e\u0421<\/td>\n<td>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u041e\u0421<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0412\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>&amp;str<\/code> \u0432 <code>CString<\/code> \u2014 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 <code>\\0<\/code><\/li>\n<li><code>CString<\/code> \u0432 <code>*const i8<\/code> \u2014 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 <code>C<\/code> \u043d\u0443\u0436\u0435\u043d \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c<\/li>\n<li><code>*const i8<\/code> \u0432 <code>&amp;CStr<\/code> \u2014 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 <code>\\0<\/code><\/li>\n<li><code>&amp;CStr<\/code> \u0432 <code>&amp;[u8]<\/code> \u2014 \u0441\u0440\u0435\u0437 \u0431\u0430\u0439\u0442\u043e\u0432 \u2014 \u044d\u0442\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f &#171;\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445&#187;<\/li>\n<li><code>&amp;[u8]<\/code> \u0432 <code>&amp;OsStr<\/code> \u2014 <code>&amp;OsStr<\/code> \u2014 \u044d\u0442\u043e \u0448\u0430\u0433 \u043d\u0430 \u043f\u0443\u0442\u0438 \u043a <code>OsString<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <a href=\"https:\/\/doc.rust-lang.org\/std\/os\/unix\/ffi\/trait.OsStrExt.html\">OsStrExt<\/a> \u0434\u043b\u044f \u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f<\/li>\n<li><code>&amp;OsStr<\/code> \u0432 <code>OsString<\/code> \u2014 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 <code>&amp;OsStr<\/code> \u043d\u0443\u0436\u043d\u043e \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0445 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>readdir<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 <a href=\"https:\/\/doc.rust-lang.org\/nomicon\/ffi.html\">Nomicon<\/a> \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u043e FFI.<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">mod ffi {     use std::os::raw::{c_char, c_int};     #[cfg(not(target_os = \"macos\"))]     use std::os::raw::{c_long, c_uchar, c_ulong, c_ushort};      \/\/ \u041d\u0435\u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 \u0442\u0438\u043f. \u0421\u043c. https:\/\/doc.rust-lang.org\/nomicon\/ffi.html.     #[repr(C)]     pub struct DIR {         _data: [u8; 0],         _marker: core::marker::PhantomData&lt;(*mut u8, core::marker::PhantomPinned)>,     }      \/\/ \u041c\u0430\u043a\u0435\u0442 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 Linux \u0434\u043b\u044f `readdir(3)`, \u0433\u0434\u0435 `ino_t` \u0438     \/\/ `off_t` \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c \u0432     \/\/ \/usr\/include\/x86_64-linux-gnu\/{sys\/types.h, bits\/typesizes.h}.     #[cfg(not(target_os = \"macos\"))]     #[repr(C)]     pub struct dirent {         pub d_ino: c_ulong,         pub d_off: c_long,         pub d_reclen: c_ushort,         pub d_type: c_uchar,         pub d_name: [c_char; 256],     }      \/\/ \u041c\u0430\u043a\u0435\u0442 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u043e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435\u0439 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 `macOS` \u0434\u043b\u044f `dir(5)`.     #[cfg(all(target_os = \"macos\"))]     #[repr(C)]     pub struct dirent {         pub d_fileno: u64,         pub d_seekoff: u64,         pub d_reclen: u16,         pub d_namlen: u16,         pub d_type: u8,         pub d_name: [c_char; 1024],     }      extern \"C\" {         pub fn opendir(s: *const c_char) -> *mut DIR;          #[cfg(not(all(target_os = \"macos\", target_arch = \"x86_64\")))]         pub fn readdir(s: *mut DIR) -> *const dirent;          \/\/ \u0421\u043c. https:\/\/github.com\/rust-lang\/libc\/issues\/414 \u0438 \u0440\u0430\u0437\u0434\u0435\u043b         \/\/ _DARWIN_FEATURE_64_BIT_INODE \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 `macOS` \u0434\u043b\u044f `stat(2)`.         \/\/         \/\/ \"\u041f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0432\u0448\u0438\u0435 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\"         \/\/ (platforms that existed before these updates were available) \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a         \/\/ macOS (\u043d\u043e \u043d\u0435 \u043a iOS, wearOS \u0438 \u0442.\u0434.) \u043d\u0430 Intel \u0438 PowerPC.         #[cfg(all(target_os = \"macos\", target_arch = \"x86_64\"))]         #[link_name = \"readdir$INODE64\"]         pub fn readdir(s: *mut DIR) -> *const dirent;          pub fn closedir(s: *mut DIR) -> c_int;     } }  use std::ffi::{CStr, CString, OsStr, OsString}; use std::os::unix::ffi::OsStrExt;  #[derive(Debug)] struct DirectoryIterator {     path: CString,     dir: *mut ffi::DIR, }  impl DirectoryIterator {     fn new(path: &amp;str) -> Result&lt;DirectoryIterator, String> {         \/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c `opendir` \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 `Ok` \u043f\u0440\u0438 \u0443\u0441\u043f\u0435\u0445\u0435         \/\/ \u0438 `Err` \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u0435         unimplemented!()     } }  impl Iterator for DirectoryIterator {     type Item = OsString;     fn next(&amp;mut self) -> Option&lt;OsString> {         \/\/ \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c `readdir` \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL         unimplemented!()     } }  impl Drop for DirectoryIterator {     fn drop(&amp;mut self) {         \/\/ \u0412\u044b\u0437\u044b\u0432\u0432\u0430\u0435\u043c `closedir` \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438         unimplemented!()     } }  fn main() -> Result&lt;(), String> {     let iter = DirectoryIterator::new(\".\")?;     println!(\"\u0444\u0430\u0439\u043b\u044b: {:#?}\", iter.collect::&lt;Vec&lt;_>>());     Ok(()) }  #[cfg(test)] mod tests {     use super::*;     use std::error::Error;      #[test]     fn test_nonexisting_directory() {         let iter = DirectoryIterator::new(\"no-such-directory\");         assert!(iter.is_err());     }      #[test]     fn test_empty_directory() -> Result&lt;(), Box&lt;dyn Error>> {         let tmp = tempfile::TempDir::new()?;         let iter = DirectoryIterator::new(             tmp.path().to_str().ok_or(\"Non UTF-8 character in path\")?,         )?;         let mut entries = iter.collect::&lt;Vec&lt;_>>();         entries.sort();         assert_eq!(entries, &amp;[\".\", \"..\"]);         Ok(())     }      #[test]     fn test_nonempty_directory() -> Result&lt;(), Box&lt;dyn Error>> {         let tmp = tempfile::TempDir::new()?;         std::fs::write(tmp.path().join(\"foo.txt\"), \"The Foo Diaries\\n\")?;         std::fs::write(tmp.path().join(\"bar.png\"), \"&lt;PNG>\\n\")?;         std::fs::write(tmp.path().join(\"crab.rs\"), \"\/\/! Crab\\n\")?;         let iter = DirectoryIterator::new(             tmp.path().to_str().ok_or(\"Non UTF-8 character in path\")?,         )?;         let mut entries = iter.collect::&lt;Vec&lt;_>>();         entries.sort();         assert_eq!(entries, &amp;[\".\", \"..\", \"bar.png\", \"crab.rs\", \"foo.txt\"]);         Ok(())     } }<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"rust\">impl DirectoryIterator {     fn new(path: &amp;str) -> Result&lt;DirectoryIterator, String> {         \/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c `opendir` \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 `Ok` \u043f\u0440\u0438 \u0443\u0441\u043f\u0435\u0445\u0435         \/\/ \u0438 `Err` \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u0435         let path =             CString::new(path).map_err(|err| format!(\"Invalid path: {err}\"))?;         \/\/ \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c: `path.as_ptr()` \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c NULL         let dir = unsafe { ffi::opendir(path.as_ptr()) };         if dir.is_null() {             Err(format!(\"Could not open {:?}\", path))         } else {             Ok(DirectoryIterator { path, dir })         }     } }  impl Iterator for DirectoryIterator {     type Item = OsString;     fn next(&amp;mut self) -> Option&lt;OsString> {         \/\/ \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c `readdir` \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL         \/\/ \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c: `self.dir` \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL         let dirent = unsafe { ffi::readdir(self.dir) };         if dirent.is_null() {             \/\/ \u041c\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0438 \u043a\u043e\u043d\u0446\u0430 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438             return None;         }         \/\/ \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c: `dirent` \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL \u0438 `dirent.d_name` \u0434\u043e\u043b\u0436\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c\u0441\u044f NUL         let d_name = unsafe { CStr::from_ptr((*dirent).d_name.as_ptr()) };         let os_str = OsStr::from_bytes(d_name.to_bytes());         Some(os_str.to_owned())     } }  impl Drop for DirectoryIterator {     fn drop(&amp;mut self) {         \/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c `closedir` \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438         if !self.dir.is_null() {             \/\/ \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0442\u044c: `self.dir` \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL             if unsafe { ffi::closedir(self.dir) } != 0 {                 panic!(\"Could not close {:?}\", self.path);             }         }     } }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043a\u043e\u043d\u0435\u0446 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u0438 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430, \u0432 \u0446\u0435\u043b\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 \u0442\u0435\u043c:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/doc.rust-lang.ru\/book\">\u041a\u043d\u0438\u0433\u0430\/\u0443\u0447\u0435\u0431\u043d\u0438\u043a \u043f\u043e Rust<\/a> (\u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435) \u2014 \u0433\u043b\u0430\u0432\u044b 7, 9, 11, 13, 14 \u0438 19<\/li>\n<li><a href=\"https:\/\/github.com\/rust-lang\/rustlings\">rustlings<\/a> \u2014 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f 10, 13, 15, 17 \u0438 18<\/li>\n<li><a href=\"https:\/\/doc.rust-lang.ru\/stable\/rust-by-example\/\">Rust \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445<\/a> (\u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435) \u2014 \u043f\u0440\u0438\u043c\u0435\u0440\u044b 10-12, 18, 21 \u0438 22<\/li>\n<li><a href=\"https:\/\/practice.rs\/why-exercise.html\">Rust by practice<\/a> \u2014 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u044f 13 \u0438 14<\/li>\n<\/ul>\n<p>  <\/p>\n<p>Happy coding!<\/p>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<p><a href=\"https:\/\/timeweb.cloud\/vds-vps?utm_source=habr&amp;utm_medium=banner&amp;utm_campaign\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/b5\/pj\/of\/b5pjofdoxth14ro-rjsrn7sbmiy.png\" data-src=\"https:\/\/habrastorage.org\/webt\/b5\/pj\/of\/b5pjofdoxth14ro-rjsrn7sbmiy.png\"\/><\/a><\/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\/801201\/\"> https:\/\/habr.com\/ru\/articles\/801201\/<\/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-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/webt\/fj\/yi\/qn\/fjyiqnduv3l-rdgxnbu_t_qpgxk.jpeg\" data-src=\"https:\/\/habrastorage.org\/webt\/fj\/yi\/qn\/fjyiqnduv3l-rdgxnbu_t_qpgxk.jpeg\" data-blurred=\"true\"\/>  <\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>Hello world!<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u0443\u044e \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u043f\u043e <a href=\"https:\/\/www.rust-lang.org\/ru\/\">Rust<\/a>.<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/790556\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/794941\/\">\u0412\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/796567\/\">\u0422\u0440\u0435\u0442\u044c\u044f \u0447\u0430\u0441\u0442\u044c<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/companies\/timeweb\/articles\/802609\/\">\u0411\u043e\u043d\u0443\u0441<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p><a href=\"https:\/\/my-js.org\/docs\/guide\/rust\/\">\u0414\u0440\u0443\u0433\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0432\u0430\u043c \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<p>\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u043d\u0430 <a href=\"https:\/\/google.github.io\/comprehensive-rust\/index.html\">Comprehensive Rust<\/a> \u2014 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435 \u043f\u043e <code>Rust<\/code> \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>Android<\/code> \u0432 <code>Google<\/code> \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043e \u043d\u0430 \u043b\u044e\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u0432\u043b\u0430\u0434\u0435\u044e\u0442 \u043b\u044e\u0431\u044b\u043c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0415\u0449\u0435 \u0440\u0430\u0437: \u044d\u0442\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043d\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043e \u043d\u0430 \u0442\u0435\u0445, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043a\u043e\u0434\u0438\u0442\u044c ?<\/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-371178","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/371178","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=371178"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/371178\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=371178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=371178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=371178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}