{"id":326420,"date":"2021-07-14T09:00:23","date_gmt":"2021-07-14T09:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=326420"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=326420","title":{"rendered":"\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 \u0444\u0443\u043d\u043a\u0446\u0438\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u041f\u043e\u0441\u043b\u0435 \u0433\u043b\u0430\u0432\u044b 4 (\u0431\u044b\u043b\u043e <a href=\"https:\/\/habr.com\/ru\/post\/566668\/\">\u0437\u0434\u0435\u0441\u044c<\/a>) \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a 10.3. \u041d\u0443 \u0430 \u043a\u0443\u0434\u0430 \u0435\u0449\u0435\u2026 \u0442\u0430\u043a\u0438\u0435 \u043d\u044b\u043d\u0447\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0430.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"problema\">\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430<\/h1>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0440\u0430\u0434\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u0442\u0435\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0433\u0440\u044b \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c. \u041f\u0440\u043e\u0441\u0442\u043e\u0439 <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=502538d7d894a794e71a0517b049ad94\" rel=\"nofollow noopener noreferrer\">\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0438\u0441\u044f\u0447\u0435\u0439 \u0441\u0441\u044b\u043b\u043a\u0438<\/a> (dangling reference):<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn main() {   let r;    {     let s = String::from(&quot;Hello&quot;);     r = &amp;s;   }    \/\/ &lt;- s will be drop()-ed here    println!(&quot;r: {}&quot;, r); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>s<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043e \u0432 \u043a\u0443\u0447\u0435, \u0437\u0430\u0442\u0435\u043c \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u043e, \u0430 <code>r<\/code> \u2014 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0438 \u0431\u0443\u0434\u0435\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u043e, \u0447\u0435\u0433\u043e \u043d\u0435\u0442. Rust \u043e\u0442\u043a\u043b\u043e\u043d\u0438\u0442 \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u044f\u0432\u043a\u0443 \u043d\u0430 \u0432\u044b\u0441\u0442\u0440\u0435\u043b \u0432 \u043d\u043e\u0433\u0443 \u0441 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e <code>s<\/code> \u043d\u0435 \u0436\u0438\u0432\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043b\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">   Compiling playground v0.0.1 (\/playground) error[E0597]: `s` does not live long enough  --&gt; src\/main.rs:6:9   | 6 |     r = &amp;s;   |         ^^ borrowed value does not live long enough 7 |   }   |   - `s` dropped here while still borrowed 8 |  9 |   println!(&quot;r: {}&quot;, r);   |                     - borrow later used here<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0448\u0442\u0443\u043a\u0438 \u0434\u0430\u0432\u043d\u043e \u043b\u043e\u0432\u044f\u0442\u0441\u044f \u0438 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0430. \u0412\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u0432\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0443, \u0440\u0435\u0444\u0435\u0440\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 (\u0442\u043e, \u043d\u0430 \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0430) \u0434\u043b\u0438\u043d\u043d\u0435\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn longest(x: &amp;String, y: &amp;String) -&gt; &amp;String {     if x.len() &gt; y.len() {         x     } else {         y     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn main() {     let short_string = String::from(&quot;Short string&quot;);         let r_longest;     {         let long_string = String::from(&quot;Long string................&quot;);         r_longest = longest(&amp;short_string, &amp;long_string);     }     println!(&quot;The longest string: {}&quot;, r_longest); }<\/code><\/pre>\n<p>  <\/p>\n<p><code>r_longest<\/code> \u043f\u043e\u043b\u0443\u0447\u0438\u0442, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 <code>long_string<\/code> \u0438 \u0431\u0443\u0434\u0435\u0442 \u0436\u0438\u0442\u044c \u043d\u0435\u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0433\u043e (\u0434\u043e\u043b\u044c\u0448\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u0435\u0444\u0435\u0440\u0435\u043d\u0442\u0430) \u2014 \u0442\u0430\u043a\u043e\u0435 \u0432 production \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e. <\/p>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f C++ \u043c\u043e\u0436\u0435\u0442 \u0438 \u0438 \u0442\u0430\u043a\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0432\u044b\u043b\u043e\u0432\u0438\u0442\u044c \u2014 \u0435\u0441\u043b\u0438 &quot;\u0437\u0430\u0439\u0434\u0435\u0442&quot; \u0432\u043d\u0443\u0442\u0440\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, PVS-Studio \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0441 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439, \u0447\u0442\u043e \u0441\u043a\u0430\u0436\u0435\u0442 <a href=\"https:\/\/habr.com\/ru\/users\/andrey2008\/\" class=\"user_link\">Andrey2008<\/a>?<\/p>\n<p>  <\/p>\n<p>Rust, \u043e\u0434\u043d\u0430\u043a\u043e, \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0432\u043d\u0443\u0442\u0440\u044c \u043d\u0435 \u0437\u0430\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u044f. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043e\u043d \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442. <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=dd21b0cd80074b39fe2858936ac4044b\" rel=\"nofollow noopener noreferrer\">\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e<\/a>\u2026 \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u043c, \u0447\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">   Compiling playground v0.0.1 (\/playground) error[E0106]: missing lifetime specifier   --&gt; src\/main.rs:12:39    | 12 | fn longest(x: &amp;String, y: &amp;String) -&gt; &amp;String {    |               -------     -------     ^ expected named lifetime parameter    |    = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or `y` help: consider introducing a named lifetime parameter    | 12 | fn longest&lt;'a&gt;(x: &amp;'a String, y: &amp;'a String) -&gt; &amp;'a String {    |           ^^^^    ^^^^^^^^^^     ^^^^^^^^^^     ^^^<\/code><\/pre>\n<p>  <\/p>\n<p>\u0423\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u0438 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435. \u041d\u0430\u043c \u0433\u043e\u0432\u043e\u0440\u044f\u0442, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0434\u043e\u043b\u0436\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0442.\u0435. \u0441\u0441\u044b\u043b\u043a\u0443), \u043d\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0441 \u043a\u0430\u043a\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u044d\u0442\u043e \u043e\u0434\u0430\u043b\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u2014 \u0441 <code>x<\/code> \u0438\u043b\u0438 <code>y<\/code>. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u0430\u0436\u0435 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u0447\u0438\u043d\u0438\u0442\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u0432\u0435\u0434\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 (lifetime parameter).<\/p>\n<p>  <\/p>\n<h1 id=\"obobschyonnye-parametry-vremeni-zhizni\">\u041e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438<\/h1>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 Rust &quot;\u043f\u043e\u043d\u044f\u043b&quot;, \u0441 \u0447\u0435\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (\u0443 \u043d\u0430\u0441 \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438). \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 generic lifetime parameters:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn longest&lt;'a&gt;(x: &amp;'a String, y: &amp;'a String) -&gt; &amp;'a String {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d \u043a\u0430\u043a \u0441 <code>x<\/code>, \u0442\u0430\u043a \u0438 \u0441 <code>y<\/code>, \u0438 \u043f\u043e\u0441\u043b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e \u0432 \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u043c \u043c\u0435\u0441\u0442\u0435 <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=82f2150c453977b417c3add3b7cfa6ad\" rel=\"nofollow noopener noreferrer\">\u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442<\/a>, \u0447\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">6 |         r_longest = longest(&amp;short_string, &amp;long_string);   |                                            ^^^^^^^^^^^^ borrowed value does not live long enough<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0440\u0430\u0433 \u043f\u043e\u0439\u043c\u0430\u043d, <a href=\"https:\/\/youtu.be\/10vdQpDJbbM?t=161\" rel=\"nofollow noopener noreferrer\">\u043f\u0438\u043b\u043e\u0442\u044b \u043c\u043e\u043b\u0447\u0430\u0442, \u0441\u043c\u043e\u0442\u0440\u044f\u0442 \u043d\u0430 \u0437\u0432\u0435\u0437\u0434\u044b, \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e. \u0412\u0441\u0435 \u0443\u043b\u044b\u0431\u0430\u044e\u0442\u0441\u044f<\/a>. \u041d\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0434\u0432\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u0430. \u041f\u0435\u0440\u0432\u044b\u0439 \u2014 \u0430 \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0431\u044b\u043b\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e \u0432\u0442\u043e\u0440\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c? \u0412\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn longest&lt;'a&gt;(x: &amp;String, y: &amp;'a String) -&gt; &amp;'a String {<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0432 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0432\u0435\u0442\u043e\u043a <code>if<\/code> \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u0442\u044c <code>x<\/code> \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438, \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u043c \u0441 \u0442\u0430\u043a\u043e\u0432\u044b\u043c \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2014 \u043a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043c\u0430\u0448\u0438\u043d\u0435\u0440\u0438\u044f Rust \u0438\u0441\u043f\u0440\u0430\u0432\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 (\u0440\u0438\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439) \u2014 \u0430 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e &quot;\u0437\u0430\u0441\u0430\u0445\u0430\u0440\u0438\u0442\u044c&quot; \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441, \u0432\u0432\u043e\u0434\u0438\u0442\u044c <code>&lt;'a&gt;<\/code> \u043d\u0435\u044f\u0432\u043d\u043e \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043a\u043e \u0432\u0441\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c, \u0430 \u0443 \u043a\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u043d\u0443\u0436\u0434\u0430, \u0442\u043e\u0442 \u043f\u0443\u0441\u0442\u044c \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0430? \u0421 \u0443\u0447\u0435\u0442\u043e\u043c \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u043c\u0435\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a (\u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u0447\u043d\u043e):<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn longest(x: &amp;String, y: &amp;String) -&gt; &amp;'y String {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0440\u0430\u0437\u0443 \u0431\u044b\u043b\u043e \u0431\u044b \u044f\u0441\u043d\u043e, \u0447\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>y<\/code> \u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u0430 \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043f\u0435\u0440\u0435\u0436\u0438\u0442\u044c (&quot;outlive&quot;)&#8230;<\/p>\n<p>  <\/p>\n<p>\u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0441\u0430\u0445\u0430\u0440\u0438\u0432\u0430\u043d\u0438\u044f Rust \u0438\u0434\u0435\u0442, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0442\u0435\u043c\u0435 \u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <strong>Lifetime Elision<\/strong>.<\/p>\n<p>  <\/p>\n<h1 id=\"pravila-neyavnogo-vyvedeniya-vremen-zhizni-lifetime-elision\">\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \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)<\/h1>\n<p>  <\/p>\n<p><strong>\u041f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e<\/strong> <del>\u0431\u043e\u0439\u0446\u043e\u0432\u0441\u043a\u043e\u0433\u043e \u043a\u043b\u0443\u0431\u0430<\/del>: \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430-\u0441\u0441\u044b\u043b\u043a\u0438 \u0441 \u043d\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0436\u0438\u0437\u043d\u0438 \u0437\u0430\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u0432\u043e\u0439 \u043d\u0435\u044f\u0432\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440:<\/p>\n<p>  <\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441\u043e \u0432\u0442\u043e\u0440\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c):<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn myfunc&lt;'a, 'b&gt;(x: &amp;'a String, y: &amp;'b String) -&gt; &amp;'b String {<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0438\u0448\u0435\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn myfunc&lt;'a&gt;(x: &amp;String, y: &amp;'a String) -&gt; &amp;'a String {<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0443, \u0438 \u043d\u0430 \u0442\u043e\u043c \u0441\u043f\u0430\u0441\u0438\u0431\u043e.<\/p>\n<p>  <\/p>\n<p><strong>\u0412\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e<\/strong>. \u0415\u0441\u043b\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0441\u0441\u044b\u043b\u043a\u0430, \u0442\u043e \u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043d\u0430 \u0432\u0441\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn myfunc&lt;'a&gt;(p1: &amp;'a str, p2: int, p3: int) -&gt; (out1: &amp;'a str, out2: &amp;'a str) { <\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0438\u0448\u0435\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn myfunc(p1: &amp;str, p2: int, p3: int) -&gt; (out1: &amp;str, out2: &amp;str) {<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e.<\/p>\n<p>  <\/p>\n<p><strong>\u0422\u0440\u0435\u0442\u044c\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e<\/strong>. \u0415\u0441\u043b\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043c\u043d\u043e\u0433\u043e \u0441\u0441\u044b\u043b\u043e\u043a, \u043d\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 <code>&amp;self<\/code> \u0438\u043b\u0438 <code>&amp;mut self<\/code>, \u0442\u043e \u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043d\u0430 \u0432\u0441\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u0441\u0435 \u0448\u0438\u043a\u0430\u0440\u043d\u043e. \u0412\u0438\u0434\u0438\u043c\u043e, \u043d\u0430\u0441 \u043a\u0430\u043a \u0431\u044b \u043f\u043e\u0434\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0442 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u041e\u041e\u041f (\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432 Rust &quot;\u043f\u043e-\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443&quot; \u0438 \u043d\u0435\u0442, \u0445\u0435-\u0445\u0435).<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0434 \u0437\u0430\u043d\u0430\u0432\u0435\u0441 \u043d\u0430\u0434\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0433\u0430\u0434\u043a\u0443 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<p>  <\/p>\n<h1 id=\"vremya-zhizni-static\">\u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 &#8216;static<\/h1>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0432\u043e\u0442 <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=6aa58ab4a39dc824c674cef679ab48f9\" rel=\"nofollow noopener noreferrer\">\u0442\u0430\u043a\u043e\u0439<\/a> \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">fn dangling_reference() -&gt; &amp;str {     let s = String::from(&quot;hello&quot;);     return &amp;s }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">error[E0106]: missing lifetime specifier  --&gt; src\/lib.rs:1:28   | 1 | fn dangling_reference() -&gt; &amp;str {   |                            ^ expected named lifetime parameter   |   = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from help: consider using the `'static` lifetime   | 1 | fn dangling_reference() -&gt; &amp;'static str {   |                            ^^^^^^^^                      ^^^^^^^^<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e \u0436\u0430\u043b\u0443\u0435\u0442\u0441\u044f, \u043c\u043e\u043b, \u043d\u0435\u043e\u0442\u043a\u0443\u0434\u0430 \u0437\u0430\u043d\u044f\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0432\u0441\u0435 \u0443\u043c\u0435\u0440\u043b\u043e. \u0418 \u043e\u043f\u044f\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435! \u2014 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u043a &#8216;static.<\/p>\n<p>  <\/p>\n<p>\u0414\u0435\u043b\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=92c5c6db940c91fab438e4253d830d6a\" rel=\"nofollow noopener noreferrer\">\u0442\u0430\u043a<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">static STATIC_STR: &amp;str = &quot;I am STATIC_STR&quot;;  fn static_reference() -&gt; &amp;'static str {     return STATIC_STR }  fn main(){     println!(&quot;static_reference: {}&quot;, static_reference()); }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u0421\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0442\u0438\u043f\u0430 String, \u043f\u043e-\u043c\u043e\u0435\u043c\u0443, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. \u041d\u043e \u044d\u0442\u043e \u043d\u0435 \u0442\u043e\u0447\u043d\u043e<\/li>\n<\/ul>\n<\/div>\n<p> \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\/post\/567596\/\"> https:\/\/habr.com\/ru\/post\/567596\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p>\u041f\u043e\u0441\u043b\u0435 \u0433\u043b\u0430\u0432\u044b 4 (\u0431\u044b\u043b\u043e <a href=\"https:\/\/habr.com\/ru\/post\/566668\/\">\u0437\u0434\u0435\u0441\u044c<\/a>) \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a 10.3. \u041d\u0443 \u0430 \u043a\u0443\u0434\u0430 \u0435\u0449\u0435\u2026 \u0442\u0430\u043a\u0438\u0435 \u043d\u044b\u043d\u0447\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0430.<\/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-326420","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/326420","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=326420"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/326420\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}