{"id":390016,"date":"2024-06-29T08:58:51","date_gmt":"2024-06-29T08:58:51","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=390016"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=390016","title":{"rendered":"<span>\u041a\u043e\u043d\u0441\u043f\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u041a\u043d\u0438\u0433\u0443 Rust:: \u0412\u0440\u0435\u043c\u0435\u043d\u0430 \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/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\">\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <a href=\"https:\/\/doc.rust-lang.ru\/book\/ch10-03-lifetime-syntax.html\" rel=\"nofollow noopener noreferrer\">10.3<\/a>. <\/p>\n<p>  <\/p>\n<p>\u041a\u041c\u0411.- \u0414\u0432\u043e\u0439\u043d\u0430\u044f \u0436\u0438\u0437\u043d\u044c.- \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u0438\u0435 \u043c\u0435\u0440\u0442\u0432\u0435\u0446\u043e\u0432.- \u041e\u0448\u0438\u0431\u043a\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.- \u0423\u0436\u0430\u0441\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 The Rustonomicon.- \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u043e\u0437\u0430\u0440\u0435\u043d\u0438\u044f.- \u0420\u0430\u0437\u0432\u044f\u0437\u043a\u0430.<\/p>\n<p>  <\/p>\n<ul>\n<li><strong>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/strong>: <a href=\"https:\/\/habr.com\/ru\/post\/567596\/\">\u0412\u0440\u0435\u043c\u0435\u043d\u0430 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a><\/li>\n<li><strong>\u041d\u0430\u0447\u0430\u043b\u043e \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/strong>: <a href=\"https:\/\/habr.com\/ru\/post\/566668\/\">\u0412\u043b\u0430\u0434\u0435\u043d\u0438\u0435<\/a><\/li>\n<\/ul>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"kmb-po-strukturam\">\u041a\u041c\u0411 \u043f\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u043c<\/h1>\n<p>  <\/p>\n<p><a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=f546df770563a3db857afe391cc84cff\" rel=\"nofollow noopener noreferrer\">\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] struct Point {     x: i32,     y: i32, }  #[derive(Debug)] struct Circle {     center: Point,     radius: i32, }  fn main(){     let p1 = Point{x:10, y:20};     println!(\"p: {:?}\", p1);      let c = Circle{ center: Point{x: 1, y:2}, radius: 3,};     println!(\"c: {:?}\", c); }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>#[derive(Debug)]<\/code> \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0439 \u043f\u0435\u0447\u0430\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 <code>{:?}<\/code><\/li>\n<li>\u0412\u0441\u0435 \u043f\u043e\u043b\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u044f\u0432\u043d\u043e \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b<\/li>\n<\/ul>\n<p>  <\/p>\n<p><a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=35675994928283170588dc57a538c4b4\" rel=\"nofollow noopener noreferrer\">\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] struct Point&lt;T> {     x: T,     y: T, }  #[derive(Debug)] struct Circle&lt;T> {     center: Point&lt;T>,     radius: T, }  fn main(){     let p_i32 = Point::&lt;i32>{x:10, y:20};     println!(\"p_i32: {:?}\", p_i32);      let p_str = Point::&lt;&amp;str>{x: \"I'm x\", y: \"I'm y\"};     println!(\"p_str: {:?}\", p_str);      let c_f64 = Circle::&lt;f64>{ center: Point{x: 1.1, y:2.2}, radius: 3.3,};     println!(\"c_f64: {:?}\", c_f64); }<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"struktury-so-ssylochnymi-polyami\">\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u043e \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438<\/h1>\n<p>  <\/p>\n<p>\u0414\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0441\u0430\u0445\u0430\u0440\u0438\u0432\u0430\u043d\u0438\u044f \u0435\u0449\u0435 \u043d\u0435 \u0434\u043e\u0448\u0435\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u044f\u0432\u043d\u043e \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0432\u0441\u0435, \u0447\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0430\u043c \u0436\u0438\u0437\u043d\u0438. <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=4df86428e53b85483fca395af38cb8ba\" rel=\"nofollow noopener noreferrer\">\u041f\u0440\u0438\u043c\u0435\u0440<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] struct Point&lt;'a, T> {     x: &amp;'a T,     y: &amp;'a T, }  #[derive(Debug)] struct Circle&lt;'a, T> {     center: Point&lt;'a, T>,     radius: &amp;'a T, }  fn main(){     let p_i32 = Point::&lt;i32>{x: &amp;10, y: &amp;20};     println!(\"p_i32: {:?}\", p_i32);      let c_f64 = Circle::&lt;f64>{ center: Point{x: &amp;1.1, y: &amp;2.2}, radius: &amp;3.3,};     println!(\"c_f64: {:?}\", c_f64); }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>&amp;10<\/code> \u2014 \u0437\u0430\u043d\u044f\u0442\u043d\u043e, Go \u0442\u0430\u043a \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 (<a href=\"https:\/\/play.golang.org\/p\/pP6NFcrDs2n\" rel=\"nofollow noopener noreferrer\">cannot take the address of 10<\/a>)<\/li>\n<li>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0435\u0440\u0430\u0437\u0440\u044b\u0432\u043d\u043e\u00a0\u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441 \u0438\u0440\u0440\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c \u0440\u0438\u0442\u0443\u0430\u043b\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f <code>'a<\/code> \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0438 \u0434\u0430\u043b\u0435\u0435 \u0432\u0435\u0437\u0434\u0435<\/li>\n<li>\u041a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0440\u0430\u043d\u0435\u0435, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>Point&lt;T>...Point::&lt;&amp;str><\/code>, \u0447\u0442\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u0434\u0430\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438, \u044f\u0432\u043d\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0430 \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u2014 \u043f\u043e\u043b \u043d\u0435 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u043b\u0441\u044f<\/li>\n<li>\u0412 \u0447\u0435\u043c \u0442\u0443\u0442 <del>\u0441\u0438\u043b\u0430<\/del> \u0441\u043c\u044b\u0441\u043b, \u0431\u0440\u0430\u0442?<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u0441\u043c\u044b\u0441\u043b \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e?<\/p>\n<p>  <\/p>\n<h1 id=\"dvoynaya-zhizn\">\u0414\u0432\u043e\u0439\u043d\u0430\u044f \u0436\u0438\u0437\u043d\u044c<\/h1>\n<p>  <\/p>\n<p>\u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e Rust \u044f \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0432\u043d\u044f\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0441\u0447\u0435\u0442, \u043d\u043e \u0437\u0430\u0442\u043e \u043e\u043d \u0435\u0441\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0442\u0430\u0440\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u0439, <a href=\"https:\/\/doc.rust-lang.org\/1.33.0\/book\/ch19-02-advanced-lifetimes.html\" rel=\"nofollow noopener noreferrer\">19.2 Advanced Lifetimes<\/a>. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0435\u0449\u0435 &#171;\u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b\u0438&#187;, \u0442\u0430\u043a \u0447\u0442\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u0435\u0433\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c, \u0437\u0430\u043e\u0434\u043d\u043e \u043f\u043e\u0434\u043f\u0440\u0430\u0432\u0438\u043b &#171;\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443&#187; \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0432\u043a\u0443\u0441\u0443.<\/p>\n<p>  <\/p>\n<p>\u0426\u0435\u043b\u044c\u044e \u0431\u044b\u043b\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c Rust \u0432\u044b\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438. \u0414\u043e\u043b\u0436\u0435\u043d \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u044d\u0442\u043e \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u2014 \u043e\u0431\u044b\u0447\u043d\u043e \u0441\u0442\u0440\u043e\u0433\u0438\u0439, \u0434\u043e \u0441\u0430\u0434\u0438\u0437\u043c\u0430, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0431\u043b\u0430\u0433\u043e\u0434\u0443\u0448\u043d\u043e \u043f\u0440\u043e\u0449\u0430\u043b \u043c\u043d\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0430\u043c\u0438. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0441\u0442\u0430\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=794abc35ac2d5596d69842f67d72dff5\" rel=\"nofollow noopener noreferrer\">\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f<\/a>. \u0412\u0438\u0434\u0438\u043c\u043e, \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0438\u0441\u0430\u0442\u0435\u043b\u0438 \u043f\u043e\u043c\u044b\u043a\u0430\u043b\u0438\u0441\u044c, \u043f\u043e\u043c\u044b\u043a\u0430\u043b\u0438\u0441\u044c\u2026 \u0434\u0430 \u0438 \u043d\u0435 \u0441\u0442\u0430\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u043e \u044d\u0442\u043e \u0432 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0436, <a href=\"https:\/\/youtu.be\/Mg7Fr3UP1pI?t=7\" rel=\"nofollow noopener noreferrer\">\u043c\u044b \u043d\u0435 \u043f\u0440\u0438\u0432\u044b\u043a\u043b\u0438 \u043e\u0442\u0441\u0442\u0443\u043f\u0430\u0442\u044c<\/a>. \u041e\u0431\u0449\u0438\u0439 \u0437\u0430\u043c\u044b\u0441\u0435\u043b \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0442\u0430\u043a\u043e\u0432 \u2014 \u0435\u0441\u0442\u044c \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0439 (<code>'s<\/code>) Parser \u0438 \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0439 (<code>'l<\/code>) Context. Parser \u0431\u0435\u0440\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 Context \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0436\u0438\u0437\u043d\u0438 Context (\u0442.\u0435. \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b Parser \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0439).<\/p>\n<p>  <\/p>\n<p>Context:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">struct Context&lt;'l> {     data: &amp;'l str, }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0435 \u0436\u0438\u0432\u0435\u0442 \u0434\u043e\u043b\u0433\u043e (<code>'l<\/code>)<\/li>\n<\/ul>\n<p>  <\/p>\n<p>Parser:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">struct Parser&lt;'s, 'l: 's> {     ctx: &amp;'s Context&lt;'l>,     internal_data: &amp;'s str, }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>struct Parser&lt;'s, 'l: 's><\/code>: \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438, \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 <code>'l<\/code> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f <code>'s<\/code> (<code>'l<\/code> outlives <code>'s<\/code>)<\/li>\n<li><code>ctx: &amp;'s Context&lt;'l><\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e <code>ctx<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0436\u0438\u0432\u0443\u0449\u0435\u0439 \u0441\u0441\u044b\u043b\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>Context<\/code> \u0441 \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u043c\u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u0432\u043d\u0443\u0442\u0440\u0438<\/li>\n<li>\u041d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u2014 \u0432\u043c\u0435\u0441\u0442\u043e <code>'s<\/code> \u0438 <code>'l<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u0438\u043c\u0435\u043d\u0430, \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, \u0442.\u0435. \u044d\u0442\u043e \u043d\u0435 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043f\u0435\u0446\u0441\u043b\u043e\u0432\u0430<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>Parser.parse()<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl&lt;'s, 'l> Parser&lt;'s, 'l> {     fn parse(&amp;self) -> &amp;'l str {         if self.ctx.data.len() > 1{             &amp;self.ctx.data[1..]         } else {             self.ctx.data         }     } }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u0421\u043c\u044b\u0441\u043b \u043c\u0435\u0442\u043e\u0434\u0430 \u2014 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u043a\u0443 <code>ctx.data<\/code> \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0430\u0439\u0442\u0430, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0430\u0439\u0442 \u0435\u0441\u0442\u044c<\/li>\n<\/ul>\n<p>  <\/p>\n<p><a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=3b84f4ca7f6c9ac22bedd6a04f491871\" rel=\"nofollow noopener noreferrer\">\u0412\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#![allow(unused)]  struct Context&lt;'l> {     data: &amp;'l str, }  struct Parser&lt;'s, 'l: 's> {     ctx: &amp;'s Context&lt;'l>,     internal_data: &amp;'s str, }  impl&lt;'s, 'l> Parser&lt;'s, 'l> {     fn parse(&amp;self) -> &amp;'l str {         if self.ctx.data.len() > 0{             &amp;self.ctx.data[1..]         } else {             self.ctx.data         }     } }  fn main(){     let working_ctx = Context{data: \"0123456\"};     let parsing_res: &amp;str;     {         let dummy = &amp;String::from(\"dummy\");         let p = Parser{ctx: &amp;working_ctx, internal_data: dummy};         parsing_res = p.parse();     }     println!(\"parsing_res: {}\", parsing_res) }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043b\u043e\u043c\u0430\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=fe5ed62c37363f05e1ebe4e9193df4fd\" rel=\"nofollow noopener noreferrer\">\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">... impl&lt;'a> Parser&lt;'a, 'a> {     fn parse(&amp;self) -> &amp;'a str { ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0443\u0442 \u043a\u0430\u043a \u0431\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f <code>Parser<\/code> \u043f\u0440\u0435\u043d\u0435\u0431\u0440\u0435\u0433 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438. \u0412\u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0443\u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u0442, \u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">26 |         let dummy = &amp;String::from(\"dummy\");    |                      ^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use ... 29 |     }    |     - temporary value is freed at the end of this statement 30 |     println!(\"parsing_res: {}\", parsing_res)    |                                 ----------- borrow later used here ...    = note: consider using a `let` binding to create a longer lived value<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0432\u043e\u0442 \u0438 \u043d\u0435 \u0443\u0433\u0430\u0434\u0430\u043b, <code>dummy<\/code> \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f! \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0441\u043e\u0432\u0435\u0442 \u043f\u0440\u043e let \u043c\u043d\u0435 \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u0435\u043d. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0437\u0430\u0433\u043d\u0430\u0442\u044c \u0432 \u0443\u0433\u043e\u043b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u043d\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u043d \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438, \u0438 \u0434\u0430\u0436\u0435, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e-\u0441\u0432\u043e\u0435\u043c\u0443 \u043f\u0440\u0430\u0432.<\/p>\n<p>  <\/p>\n<p>\u0421\u0442\u0440\u043e\u043a\u0430 <code>let p = Parser{ctx: &amp;working_ctx, internal_data: dummy};<\/code> \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u0441 <code>p<\/code> \u0434\u0432\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438, \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u043e\u0442 <code>dummy<\/code> \u0438 \u0434\u043b\u0438\u043d\u043d\u043e\u0435 \u043e\u0442 <code>working_ctx<\/code>, \u043d\u043e \u043f\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 <code>parse()<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u044c, \u0441 \u043a\u0430\u043a\u0438\u043c \u0438\u0437 \u043d\u0438\u0445 \u0441\u0432\u044f\u0437\u0430\u043d \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0442\u0430\u043a \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 <del>\u0437\u043e\u043b<\/del> \u0432\u0440\u0435\u043c\u0435\u043d \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435, \u0442.\u0435. <code>dummy<\/code>. C \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 <code>dummy<\/code> \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0439 <code>parsing_res<\/code>, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u0435\u043b\u044c\u0437\u044f. \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0436\u0435\u043b\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435\u0433\u043e, \u0441 lifetime \u0442\u0430\u043a\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0435\u0441\u0442\u044c, \u044d\u0442\u0438\u043c \u0434\u0430\u0436\u0435 <a href=\"https:\/\/ethz.ch\/content\/dam\/ethz\/special-interest\/infk\/chair-program-method\/pm\/documents\/Education\/Theses\/David_Blaser_BA_Report.pdf\" rel=\"nofollow noopener noreferrer\">\u0440\u0435\u0431\u044f\u0442\u0430 \u0438\u0437 Z\u00fcrich \u043e\u0437\u0430\u0431\u043e\u0447\u0435\u043d\u044b<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041b\u0430\u0434\u043d\u043e, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u043c\u0430\u0442\u044c \u0443\u0436\u0435 \u0441\u043b\u043e\u043c\u0430\u043d\u043d\u043e\u0435, \u0447\u0442\u043e\u0431\u044b \u043c\u0438\u043d\u0443\u0441 \u043d\u0430 \u043c\u0438\u043d\u0443\u0441 \u0434\u0430\u043b \u043f\u043b\u044e\u0441.<\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c dummy <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=c437a43a5b2302435c953c157dcb9e75\" rel=\"nofollow noopener noreferrer\">\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">... \/\/ let dummy = &amp;String::from(\"dummy\"); let dummy = \"dummy\"; ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435 \u0435\u0449\u0435 &#171;\u0437\u0430\u043a\u043e\u0440\u043e\u0447\u0435\u043d\u044b&#187; \u0432\u0440\u0435\u043c\u0435\u043d\u0430 (<code>impl&lt;'a> Parser&lt;'a, 'a><\/code>). \u0412 \u0447\u0435\u043c \u0442\u0443\u0442 \u0434\u0435\u043b\u043e? \u0412\u0438\u0434\u0430\u0442\u044c, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b, \u043d\u043e \u0438 data-flow analysis.<\/p>\n<p>  <\/p>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>dummy<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 <code>'static<\/code> (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u043e\u043e\u0431\u0449\u0435 \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e &#171;\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442&#187;, \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 &#171;\u0442\u0443\u0445\u043d\u0435\u0442&#187;) \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>p<\/code>, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u043b\u0438\u0431\u043e \u0441\u043e <code>'static<\/code>, \u043b\u0438\u0431\u043e \u0441 <code>working_ctx<\/code>. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 <code>p.parse()<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e &#171;\u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0442\u044c&#187; \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c <code>working_ctx<\/code>, \u0438 \u043a\u043e\u0434 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e &#171;\u0441\u0435\u0440\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f&#187; \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u043e\u0439 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d.<\/p>\n<p>  <\/p>\n<p>\u0422\u0443\u0442, \u043a\u0441\u0442\u0430\u0442\u0438, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u043d\u044f\u0442\u0438\u0435 &#171;\u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438&#187; \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043d\u0435 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043a \u0441\u0441\u044b\u043b\u043a\u0430\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442&#8230;<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=cb51fe853126c1d0a6eeb0d2a456a3b8\" rel=\"nofollow noopener noreferrer\">\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/a>, \u0443\u0431\u0440\u0430\u0442\u044c <code>internal_data<\/code> \u0438\u0437 <code>Parser<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">... struct Parser&lt;'s, 'l: 's> {     ctx: &amp;'s Context&lt;'l>, } ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c <code>p<\/code> \u0443 \u043d\u0430\u0441 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a: <code>let p = Parser{ctx: &amp;working_ctx};<\/code>, \u0442.\u0435. \u043e\u043d\u0430 \u0441\u0432\u044f\u0437\u0430\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u043c <code>working_ctx<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u043b\u044e\u0431\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 <code>Parser<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043c \u0436\u0435, \u0433\u0434\u0435 \u0438 <code>working_ctx<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435? <a href=\"https:\/\/www.youtube.com\/watch?v=f2YKwtDXOQo\" rel=\"nofollow noopener noreferrer\">\u041d\u0435\u0442, \u043d\u0435 \u0432\u0441\u0435<\/a>.<\/p>\n<p>  <\/p>\n<h1 id=\"struktury-so-ssylkami-v-parametrah-funkciy\">\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/h1>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u044c\u0442\u0435\u0441\u044c, \u0441\u0435\u0439\u0447\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0433\u0440\u0443\u0441\u0442\u043d\u043e. <\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a <a href=\"https:\/\/doc.rust-lang.ru\/book\/ch10-03-lifetime-syntax.html#%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0-%D0%BD%D0%B5%D1%8F%D0%B2%D0%BD%D0%BE%D0%B3%D0%BE-%D0%B2%D1%8B%D0%B2%D0%B5%D0%B4%D0%B5%D0%BD%D0%B8%D1%8F-%D0%B2%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%B8-%D0%B6%D0%B8%D0%B7%D0%BD%D0%B8\" rel=\"nofollow noopener noreferrer\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u043d\u0435\u044f\u0432\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d \u0436\u0438\u0437\u043d\u0438 (lifetime elision):<\/p>\n<p>  <\/p>\n<blockquote><p><strong>\u041f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e<\/strong> \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u043e\u0439, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, <strong>\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438<\/strong>: fn foo&lt;&#8216;a>(x: &amp;&#8217;a i32); \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441 \u0434\u0432\u0443\u043c\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u0434\u0432\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438: fn foo&lt;&#8216;a, &#8216;b>(x: &amp;&#8217;a i32, y: &amp;&#8217;b i32) \u2014 \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  <strong>\u0412\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e<\/strong> \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 <strong>\u0442\u043e\u0447\u043d\u043e \u043e\u0434\u0438\u043d \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438, \u0442\u043e \u0435\u0433\u043e \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u043c \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c<\/strong>: <code>fn foo&lt;'a>(x: &amp;'a i32) -> &amp;'a i32<\/code>.<\/p><\/blockquote>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=f4a59d92919dffe6f228c8dab20fef67\" rel=\"nofollow noopener noreferrer\">\u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">... struct Circle&lt;'a, T> {     center: Point&lt;'a, T>,     radius: &amp;'a T, }  fn get_radius&lt;T>(c: &amp;Circle&lt;T>) -> &amp;T {     c.radius }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043b\u0435\u0434\u0438\u0442\u0435 \u0437\u0430 \u0440\u0443\u043a\u0430\u043c\u0438. \u0412\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043e\u0434\u0438\u043d? \u0414\u0430. Ergo \u2014 \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u0438\u043d \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0432\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u0430\u0432\u0438\u043b\u0443, \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u043c \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c. \u0422\u0430\u043a \u043f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435&#8230;:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">15 | fn get_radius&lt;T>(c: &amp;Circle&lt;T>) -> &amp;T {    |                     ----------     ^ expected named lifetime parameter<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e. \u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u044d\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430? \u041d\u0435\u0442, \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430, \u0432\u043e\u0442 <a href=\"https:\/\/doc.rust-lang.org\/book\/ch10-03-lifetime-syntax.html#lifetime-elision\" rel=\"nofollow noopener noreferrer\">\u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b<\/a>:<\/p>\n<p>  <\/p>\n<blockquote><p>The first rule is that each parameter that is a reference gets its own lifetime parameter. In other words, a <strong>function with one parameter gets one lifetime parameter<\/strong>: fn foo&lt;&#8216;a>(x: &amp;&#8217;a i32); a function with two parameters gets two separate lifetime parameters: fn foo&lt;&#8216;a, &#8216;b>(x: &amp;&#8217;a i32, y: &amp;&#8217;b i32); and so on.<\/p>\n<p>  The second rule is <strong>if there is exactly one input lifetime parameter, that lifetime is assigned to all output lifetime parameters<\/strong>: fn foo&lt;&#8216;a>(x: &amp;&#8217;a i32) -> &amp;&#8217;a i32.<\/p><\/blockquote>\n<p>\u042d\u0442\u0430 \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 \u043f\u043e\u0448\u043b\u0430 \u0433\u0443\u043b\u044f\u0442\u044c \u043f\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430\u043c, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0443\u0442\u0438\u0440\u0443\u044f \u043f\u043e \u043f\u0443\u0442\u0438, \u0441\u043c., \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/learning-rust.github.io\/docs\/c3.lifetimes.html\" rel=\"nofollow noopener noreferrer\">\u0442\u0443\u0442<\/a>: &#171;&#8230;only one input parameter passes by reference&#8230;&#187;.<\/p>\n<p>  <\/p>\n<p>\u0413\u0434\u0435 \u043f\u0440\u0430\u0432\u0434\u0430? \u0412\u0435\u0441\u0442\u0438\u043c\u043e, \u0432 <a href=\"http:\/\/web.mit.edu\/rust-lang_v1.25\/arch\/amd64_ubuntu1404\/share\/doc\/rust\/html\/book\/first-edition\/lifetimes.html#lifetime-elision\" rel=\"nofollow noopener noreferrer\">&#171;\u0441\u0442\u0430\u0440\u043e\u043c \u0443\u0447\u0435\u0431\u043d\u0438\u043a\u0435&#187;<\/a> \u043f\u043e\u043b\u0443\u0447\u0448\u0435, \u0442\u043e\u0433\u0434\u0430 \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0431\u044b\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0435, \u0438 \u0432\u0441\u0435 \u0442\u0430\u043a\u043e\u0435 \u2014 \u043d\u043e \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0442\u0443\u043c\u0430\u043d\u043d\u043e, \u0431\u0435\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0435\u0433\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430. \u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0442\u0430\u043a\u0436\u0435 <a href=\"https:\/\/doc.rust-lang.org\/nomicon\/lifetime-elision.html\" rel=\"nofollow noopener noreferrer\">\u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043e<\/a> \u0432 \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u043c \u0438 \u0443\u0436\u0430\u0441\u043d\u043e\u043c The Rustonomicon, \u043d\u043e \u0443\u0436\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438. \u042d\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u0446\u0438\u0442\u0438\u0440\u0443\u0435\u0442 \u0443\u0432. <a href=\"https:\/\/habr.com\/ru\/users\/psyhaste\/\" class=\"user_link\">PsyHaSTe<\/a> <a href=\"https:\/\/habr.com\/ru\/post\/434200\/\">\u0442\u0443\u0442<\/a>, \u043f\u0440\u0430\u0432\u0434\u0430, \u043f\u0440\u0438 \u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0443:<\/p>\n<p>  <\/p>\n<blockquote><p>\u2026 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0432\u0441\u0435\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0440\u0430\u0432\u043d\u044b\u043c\u0438&#8230;<\/p><\/blockquote>\n<p>\u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u044d\u0442\u043e \u0438 \u043e\u043f\u0435\u0447\u0430\u0442\u043a\u0430, \u043e\u0434\u043d\u0443 \u0431\u0443\u043a\u0432\u0443 \u0432\u0441\u0435\u0433\u043e-\u0442\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c\u2026 <a href=\"https:\/\/youtu.be\/DP8FeT7hJXU?t=44\" rel=\"nofollow noopener noreferrer\">\u043d\u043e \u0432\u0435\u0434\u044c \u043a\u0442\u043e-\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d<\/a>, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u0434\u0430 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0438\u0433\u0434\u0435 \u043d\u0435\u0442\u2026 \u0418\u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<blockquote><p><strong>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 1<\/strong>. \u041d\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0430 \u0436\u0438\u0437\u043d\u0438 \u0432\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438 \u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f <strong>\u0440\u0430\u0437\u043d\u044b\u043c\u0438<\/strong>.<br \/>  <strong>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 2<\/strong>. \u0415\u0441\u043b\u0438 \u0432\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043e\u0434\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438, \u0442\u043e \u043e\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043d\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445.<br \/>  <strong>\u041f\u0440\u0430\u0432\u0438\u043b\u043e 3<\/strong>. \u0415\u0441\u043b\u0438 \u0432\u043e \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0435\u0441\u0442\u044c <code>&amp;self<\/code> \u0438\u043b\u0438 <code>&amp;mut self<\/code>, \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043d\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d \u0432 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445.<\/p><\/blockquote>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u044f\u0442\u044c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0440\u0435\u043c\u0435\u043d \u0436\u0438\u0437\u043d\u0438 <strong>\u043c\u043e\u0436\u043d\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e<\/strong> \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445? <strong>\u0414\u0432\u0430<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn get_radius&lt;'a, 'b, T>(c: &amp;'a Circle&lt;'b, T>) -> &amp;T {     c.radius }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a \u043e\u043d\u0438 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c &#171;\u0434\u043b\u044f \u0441\u0435\u0431\u044f&#187; \u043f\u043e \u041f\u0440\u0430\u0432\u0438\u043b\u0443 1, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u041f\u0440\u0430\u0432\u0438\u043b\u043e 2 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041a\u0430\u043a \u043f\u043e\u0447\u0438\u043d\u0438\u0442\u044c?<\/p>\n<p>  <\/p>\n<p>\u0423 \u043d\u0430\u0441 \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u2014 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 <code>c<\/code> \u0438\u043b\u0438 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 \u0441\u0441\u044b\u043b\u043e\u043a \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u043e\u0433\u043e, \u043d\u0430 \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 <code>\u0441<\/code>. <\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn get_radius&lt;'a, 'b, T>(c: &amp;'a Circle&lt;'b, T>) -> &amp;'a T {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn get_radius&lt;'c, T>(c: &amp;'c Circle&lt;T>) -> &amp;'c T {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn get_radius&lt;'a, 'b, T>(c: &amp;'a Circle&lt;'b, T>) -> &amp;'b T {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn get_radius&lt;'circle, T>(c: &amp;Circle&lt;'circle, T>) -> &amp;'circle T {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=76cdfdc24549be56aa5064cd87379966\" rel=\"nofollow noopener noreferrer\">\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">... fn get_radius&lt;T>(c: Circle&lt;T>) -> &amp;T {     c.radius }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043d\u0435\u0442 \u043d\u0438 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0438 \u0432\u0440\u0435\u043c\u0435\u043d, \u043f\u043e\u0447\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442? \u0410 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u041f\u0440\u0430\u0432\u0438\u043b\u043e 2:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn get_radius&lt;'a, T>(c: Circle&lt;'a, T>) -> &amp;T {     c.radius }<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"razmyshleniya-pro-arhitekturu-prilozheniya\">\u0420\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h1>\n<p>  <\/p>\n<p>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0438, \u0447\u0442\u043e \u043d\u0435\u043c\u0430\u043b\u043e\u0432\u0430\u0436\u043d\u043e, \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0447\u0442\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445 \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u0447\u0438\u0441\u043b\u0430 \u044d\u0442\u0438\u0445 \u0441\u0430\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0440\u0430\u0441\u0442\u0435\u0442 \u044d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e (\u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043a\u0440\u0443\u0447\u0435!), \u0442\u0430\u043a \u0447\u0442\u043e, \u041a\u041c\u041a, \u043b\u0443\u0447\u0448\u0435 \u0438\u0437\u0431\u0435\u0433\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438, \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 (S \u2014 <strong>S<\/strong>OLID)<\/li>\n<li>&#171;\u0410\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c&#187; \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439\/\u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/li>\n<li>\u0415\u0441\u0442\u044c \u0434\u0430\u0436\u0435 <a href=\"https:\/\/users.rust-lang.org\/t\/perpetual-n00b-struggling-with-ownership-again\/46920\/4\" rel=\"nofollow noopener noreferrer\">\u0442\u0430\u043a\u043e\u0435 \u043c\u043d\u0435\u043d\u0438\u0435<\/a>: You&#8217;re not allowed to use references in structs until you think Rust is easy&#8230;Use Box or Arc to store things in structs &#171;by reference&#187; (\u043f\u0440\u043e <code>Box<\/code> \u0438 <code>Arc<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445)<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u0441\u0432\u0435\u0442\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e <code>Parser<\/code> \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=135fbaa29b5f1216bc9926792c3dd5aa\" rel=\"nofollow noopener noreferrer\">\u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">struct Context&lt;'a> {     data: &amp;'a str, }  struct Parser&lt;'a>  {     internal_data: &amp;'a str, }  impl&lt;'s, 'l: 's> Parser&lt;'s> {     fn parse(&amp;self, ctx: &amp;'l Context) -> &amp;'l str { ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043b\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <a href=\"https:\/\/doc.rust-lang.org\/edition-guide\/rust-2018\/ownership-and-lifetimes\/the-anonymous-lifetime.html\" rel=\"nofollow noopener noreferrer\">anonymous lifetime<\/a>, \u0442\u0430\u043a (\u043d\u043e \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d):<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">... impl Parser&lt;'_> {     fn parse&lt;'l>(&amp;self, ctx: &amp;'l Context) -> &amp;'l str { ...<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u041c\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <code>Context<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>Parser<\/code>, \u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043f\u0440\u044f\u043c\u043e \u0432 \u043c\u0435\u0442\u043e\u0434 <code>parse()<\/code><\/li>\n<li>\u0412 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f <code>Parser<\/code> \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443, \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>parse()<\/code> \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>ctx<\/code><\/li>\n<li>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0441\u043e\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0430 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043e\u043d\u0438 \u0440\u0430\u0437\u043d\u044b\u0435. Parser \u0436\u0438\u0432\u0435\u0442 \u0434\u043e\u043b\u044c\u0448\u0435 Context? \u2014 \u041d\u0443 \u043e\u043a, \u043f\u043e\u0447\u0435\u043c\u0443 \u043d\u0435\u0442. \u0413\u043b\u0430\u0432\u043d\u043e\u0435, \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0431\u043e\u043b\u0435\u0435 &#171;\u0448\u0438\u0440\u043e\u043a\u043e\u0439&#187; \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u0447\u0435\u043c Context, \u043d\u043e \u0442\u0443\u0442-\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0437\u0430 \u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u0438\u0442!<\/li>\n<\/ul>\n<p>  <\/p>\n<h1 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u041a\u043e\u043d\u0441\u043f\u0435\u043a\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0434\u043b\u0438\u043d\u043d\u0435\u0435 \u043b\u0435\u043a\u0446\u0438\u0438, \u043d\u043e \u044d\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u2014 \u0437\u0430\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u0438\u0434\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c &#171;\u0437\u0430\u0447\u0435\u0442&#187;\u043f\u043e 10.3.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=iXQAfWTRZvI&amp;t=743s\" rel=\"nofollow noopener noreferrer\">\u041f\u0440\u043e\u0432\u0438\u0434\u0435\u043d\u0438\u044e \u043f\u0440\u0435\u043f\u043e\u0440\u0443\u0447\u0430\u044e \u0432\u0430\u0441<\/a>, \u0434\u0435\u0442\u0438 \u043c\u043e\u0438, \u0438 \u0437\u0430\u043a\u043b\u0438\u043d\u0430\u044e: \u043e\u0441\u0442\u0435\u0440\u0435\u0433\u0430\u0439\u0442\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0438 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445. \u042d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0431\u044b\u043b\u0430 \u0448\u0443\u0442\u043a\u0430. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u2014 praemonitus praemunitus, forewarned is forearmed \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/youtu.be\/tYc2jQaM8gM?t=37\" rel=\"nofollow noopener noreferrer\">Stay tuned<\/a>.<\/p>\n<p>  <\/p>\n<p><strong>PS: \u0414\u0430\u043b\u0435\u0435<\/strong>: <a href=\"https:\/\/habr.com\/ru\/post\/573422\/\">\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u0443\u0447\u0435\u0439<\/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\/569496\/\"> https:\/\/habr.com\/ru\/articles\/569496\/<\/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\">\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <a href=\"https:\/\/doc.rust-lang.ru\/book\/ch10-03-lifetime-syntax.html\" rel=\"nofollow noopener noreferrer\">10.3<\/a>. <\/p>\n<p>  <\/p>\n<p>\u041a\u041c\u0411.- \u0414\u0432\u043e\u0439\u043d\u0430\u044f \u0436\u0438\u0437\u043d\u044c.- \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u0438\u0435 \u043c\u0435\u0440\u0442\u0432\u0435\u0446\u043e\u0432.- \u041e\u0448\u0438\u0431\u043a\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.- \u0423\u0436\u0430\u0441\u0430\u044e\u0449\u0438\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 The Rustonomicon.- \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u043e\u0437\u0430\u0440\u0435\u043d\u0438\u044f.- \u0420\u0430\u0437\u0432\u044f\u0437\u043a\u0430.<\/p>\n<p>  <\/p>\n<ul>\n<li><strong>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/strong>: <a href=\"https:\/\/habr.com\/ru\/post\/567596\/\">\u0412\u0440\u0435\u043c\u0435\u043d\u0430 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a><\/li>\n<li><strong>\u041d\u0430\u0447\u0430\u043b\u043e \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/strong>: <a href=\"https:\/\/habr.com\/ru\/post\/566668\/\">\u0412\u043b\u0430\u0434\u0435\u043d\u0438\u0435<\/a><\/li>\n<\/ul>\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-390016","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/390016","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=390016"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/390016\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=390016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=390016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=390016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}