{"id":271528,"date":"2016-01-03T02:37:02","date_gmt":"2016-01-02T23:37:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=271528"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=271528","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 Rust, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 String \u0438\u043b\u0438 &#038;str"},"content":{"rendered":"<br \/>\n<h3>\u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430<\/h3>\n<p>  \u0421\u0442\u0430\u0442\u044c\u044f \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0435\u0440\u0438\u0438 \u043f\u043e\u0441\u0442\u043e\u0432, \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0436\u0435\u0439 \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043d\u0438\u043c\u0438 \u0438\u0434\u0438\u043e\u043c Rust \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0431\u0435\u0441\u0441\u043f\u043e\u0440\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u043a\u0430\u043a \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u043d\u0430 Rust, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0442\u0435\u0445, \u0447\u0442\u043e \u0443\u0436\u0435 \u0443\u0441\u043f\u0435\u043b \u0441\u0435\u0431\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u043d\u043e \u0435\u0449\u0451 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043e\u0441\u0432\u043e\u0438\u043b\u0441\u044f \u0441 \u0431\u043e\u0433\u0430\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0442\u0438\u043f\u0430\u0436\u0435\u0439. \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u043e\u043f\u0435\u0447\u0430\u0442\u043e\u043a \u0432 \u043a\u043e\u0434\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430, \u043e\u0434\u043d\u0430\u043a\u043e \u0432 \u043e\u0431\u0449\u0435\u043c \u0438 \u0446\u0435\u043b\u043e\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0438 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435, \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u043e\u0434 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u00ab\u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u00bb, \u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u044e\u0442 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f.  <\/p>\n<hr\/>\n<p>  \u0412 \u043c\u043e\u0451\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c <a href=\"http:\/\/hermanradtke.com\/2015\/05\/03\/string-vs-str-in-rust-functions.html\">\u043f\u043e\u0441\u0442\u0435<\/a> \u043c\u044b \u043c\u043d\u043e\u0433\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>&str<\/code> \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0445 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b. \u0411\u043b\u0438\u0436\u0435 \u043a \u043a\u043e\u043d\u0446\u0443 \u043f\u043e\u0441\u0442\u0430 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043b\u0438, \u043a\u043e\u0433\u0434\u0430 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>String<\/code>, \u0430 \u043a\u043e\u0433\u0434\u0430 <code>&str<\/code> \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445 (<code>struct<\/code>). \u0425\u043e\u0442\u044f \u044f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u0441\u043e\u0432\u0435\u0442 \u0445\u043e\u0440\u043e\u0448, \u043d\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>&str<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>String<\/code> \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e. \u0414\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433\u0430\u044f \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u0442\u0438\u043f\u0430 String<\/h3>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>Person<\/code>, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u043d\u0438\u0436\u0435. \u0414\u043b\u044f \u0446\u0435\u043b\u0435\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0432 \u043f\u043e\u043b\u0435 <code>name<\/code> \u0435\u0441\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c. \u041c\u044b \u0440\u0435\u0448\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>String<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>&str<\/code>.<\/p>\n<pre><code class=\"rust\">struct Person {     name: String, } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>new()<\/code>. \u0421\u043b\u0435\u0434\u0443\u044f \u0441\u043e\u0432\u0435\u0442\u0443 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0430, \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0451\u043c \u0442\u0438\u043f <code>&str<\/code>:<\/p>\n<pre><code class=\"rust\">impl Person {     fn new(name: &amp;str) -&gt; Person {         Person { name: name.to_string() }     } } <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u043e \u0432\u044b\u0437\u043e\u0432\u0435 <code>.to_string()<\/code> \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>new()<\/code> <i>(\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0437\u0434\u0435\u0441\u044c \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <a href=\"http:\/\/doc.rust-lang.org\/stable\/std\/borrow\/trait.ToOwned.html#method.to_owned\"><code>to_owned()<\/code><\/a>, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u0435\u0442\u043e\u0434 <a href=\"http:\/\/doc.rust-lang.org\/stable\/std\/string\/trait.ToString.html#tymethod.to_string\"><code>to_string()<\/code><\/a> \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0442\u044f\u0436\u0451\u043b\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430, \u0430 <code>to_owned()<\/code> \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u0441\u0440\u0435\u0437 <code>&str<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <code>String<\/code> \u2014 \u043f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432.)<\/i>. \u041e\u0434\u043d\u0430\u043a\u043e, \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0436\u0435\u043b\u0430\u0442\u044c \u043b\u0443\u0447\u0448\u0435\u0433\u043e. \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u043b, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c <code>Person<\/code> \u0442\u0430\u043a: <code>Person::new(&quot;Herman&quot;)<\/code>. \u041d\u043e \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432\u043b\u0430\u0434\u0435\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 <code>String<\/code>, \u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0451:<\/p>\n<pre><code class=\"rust\">let name = &quot;Herman&quot;.to_string(); let person = Person::new(name.as_ref()); <\/code><\/pre>\n<p>  \u041f\u043e\u0445\u043e\u0436\u0435, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0431\u044b \u043c\u044b \u0445\u043e\u0434\u0438\u043c \u043a\u0440\u0443\u0433\u0430\u043c\u0438. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <code>String<\/code>, \u0437\u0430\u0442\u0435\u043c \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>as_ref()<\/code> \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0435\u0451 \u0432 <code>&str<\/code>, \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u0435\u0451 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 <code>String<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <code>new()<\/code>. \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>String<\/code>, \u0432\u0440\u043e\u0434\u0435 <code>fn new(name: String) -&gt; Person<\/code>, \u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>.to_string()<\/code>, \u0435\u0441\u043b\u0438 \u0442\u043e\u0442 \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c <code>Person<\/code> \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u0430.<\/p>\n<h3>\u041a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Into<\/h3>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0440\u043e\u0449\u0435 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"http:\/\/doc.rust-lang.org\/nightly\/core\/convert\/trait.Into.html\">\u0442\u0438\u043f\u0430\u0436\u0430 Into<\/a>. \u042d\u0442\u043e\u0442 \u0442\u0438\u043f\u0430\u0436 \u0431\u0443\u0434\u0435\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>&str<\/code> \u0432 <code>String<\/code>. \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c <code>String<\/code>, \u0442\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0441\u0438\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<pre><code class=\"rust\">struct Person {     name: String }  impl Person {     fn new&lt;S: Into&lt;String&gt;&gt;(name: S) -&gt; Person {         Person { name: name.into() }     } }  fn main() {     let person = Person::new(&quot;Herman&quot;);     let person = Person::new(&quot;Herman&quot;.to_string()); } <\/code><\/pre>\n<p>  \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b <code>new()<\/code> \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0439. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/kgv.gitbooks.io\/rust_book_ru\/content\/src\/generics.html\">\u043e\u0431\u043e\u0431\u0449\u0451\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b<\/a> (<a href=\"http:\/\/doc.rust-lang.org\/nightly\/book\/generics.html\">\u0430\u043d\u0433\u043b.<\/a>) \u0438 <a href=\"https:\/\/kgv.gitbooks.io\/rust_book_ru\/content\/src\/traits.html\">\u0442\u0438\u043f\u0430\u0436\u0438<\/a> (<a href=\"http:\/\/doc.rust-lang.org\/nightly\/book\/traits.html\">\u0430\u043d\u0433\u043b.<\/a>), \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c Rust, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u0438\u043f <code>S<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u0430\u0436 <code>Into<\/code> \u0434\u043b\u044f \u0442\u0438\u043f\u0430 <code>String<\/code>. \u0422\u0438\u043f <code>String<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>Into&lt;String&gt;<\/code> \u043a\u0430\u043a \u043f\u0443\u0441\u0442\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>String<\/code> \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043d\u0430 \u0440\u0443\u043a\u0430\u0445. \u0422\u0438\u043f <code>&str<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>Into&lt;String&gt;<\/code> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e \u0436\u0435 <code>.to_string()<\/code> <i>(\u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 <a href=\"https:\/\/github.com\/rust-lang\/rust\/blob\/f963eb2870f6e2b972cd9d432dc0ece954ab6452\/src%2Flibcollections%2Fstring.rs#L1718-L1720\">\u043d\u0435\u0442<\/a> \u2014 \u043f\u0440\u0438\u043c. \u043f\u0435\u0440\u0435\u0432.)<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043d\u0430\u0447\u0430\u043b\u0430 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>new()<\/code>. \u0422\u0430\u043a \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0438\u0437\u0431\u0435\u0433\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <code>.to_string()<\/code>, \u0430 \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043c\u0435\u0442\u043e\u0434\u0430. \u0423 \u0432\u0430\u0441 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441, \u043d\u0435 \u0432\u0440\u0435\u0434\u0438\u0442 \u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>Into&lt;String&gt;<\/code> \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0438 \u043e\u0442\u0432\u0435\u0442 \u2014 \u043d\u0435\u0442. Rust \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"https:\/\/kgv.gitbooks.io\/rust_book_ru\/content\/src\/trait-objects.html#\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f-\u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f\">\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e<\/a> (<a href=\"http:\/\/doc.rust-lang.org\/nightly\/book\/trait-objects.html#static-dispatch\">\u0430\u043d\u0433\u043b.<\/a>) \u0438 <a href=\"http:\/\/stackoverflow.com\/a\/14198060\/775246\">\u043c\u043e\u043d\u043e\u043c\u043e\u0440\u0444\u0438\u0437\u0430\u0446\u0438\u044e<\/a> \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0441\u0435\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438.<\/p>\n<p>  \u0422\u0430\u043a\u0438\u0435 \u0441\u043b\u043e\u0432\u0430, \u043a\u0430\u043a <i>\u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/i> \u0438\u043b\u0438 <i>\u043c\u043e\u043d\u043e\u043c\u043e\u0440\u0444\u0438\u0437\u0430\u0446\u0438\u044f<\/i> \u043c\u043e\u0433\u0443\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0431\u0438\u0442\u044c \u0432\u0430\u0441 \u0441 \u0442\u043e\u043b\u043a\u0443, \u043d\u043e \u043d\u0435 \u0432\u043e\u043b\u043d\u0443\u0439\u0442\u0435\u0441\u044c. \u0412\u0441\u0451, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u0442\u0430\u043a \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0438 <code>String<\/code>, \u0438 <code>&str<\/code>. \u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u0443\u043c\u0430\u0435\u0442\u0435, \u0447\u0442\u043e <code>fn new&lt;S: Into&lt;String&gt;&gt;(name: S) -&gt; Person<\/code> \u2014 \u043e\u0447\u0435\u043d\u044c \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441, \u0442\u043e \u0434\u0430, \u0432\u044b \u043f\u0440\u0430\u0432\u044b. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432\u0430\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 <code>Into&lt;String&gt;<\/code> \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e. \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430\u0436\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Rust. \u0412\u044b \u0441\u0430\u043c\u0438 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0435\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0431\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u0438. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0442\u0438\u043f\u0430\u0436\u0438, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0438\u0445 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438, \u0438 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u043d\u0430 <a href=\"https:\/\/crates.io\/\">crates.io<\/a>. \u0412\u0441\u044f \u044d\u0442\u0430 \u043c\u043e\u0449\u044c, \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0435\u043d\u043d\u0430\u044f \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u043a\u043e\u0434\u0435, \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 Rust \u0442\u0430\u043a\u0438\u043c \u0432\u043e\u0441\u0445\u0438\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u044f\u0437\u044b\u043a\u043e\u043c.<\/p>\n<h3>\u0414\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c Person::new()<\/h3>\n<p>  \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 <i>where<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u0447\u0438\u0442\u0430\u0442\u044c, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439:<\/p>\n<pre><code class=\"rust\">struct Person { name: String,  }  impl Person {     fn new&lt;S&gt;(name: S) -&gt; Person where S: Into&lt;String&gt; {         Person { name: name.into() }     } } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0427\u0442\u043e \u0435\u0449\u0451 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c<\/h3>\n<p>  <\/p>\n<ul>\n<li><a href=\"http:\/\/hermanradtke.com\/2015\/05\/03\/string-vs-str-in-rust-functions.html\"><code>String<\/code> \u0438\u043b\u0438 <code>&str<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 Rust<\/a> <i>(\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0441\u044f \u043a \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0443)<\/i><\/li>\n<li><a href=\"http:\/\/hermanradtke.com\/2015\/05\/29\/creating-a-rust-function-that-returns-string-or-str.html\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 Rust, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 <code>&str<\/code> \u0438\u043b\u0438 <code>String<\/code><\/a> <i>(\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0441\u044f \u043a \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0443)<\/i><\/li>\n<\/ul>\n<div class=\"clear\"><\/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=\"http:\/\/habrahabr.ru\/post\/274455\/\"> http:\/\/habrahabr.ru\/post\/274455\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<br \/>\n<h3>\u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430<\/h3>\n<p>  \u0421\u0442\u0430\u0442\u044c\u044f \u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0441\u0435\u0440\u0438\u0438 \u043f\u043e\u0441\u0442\u043e\u0432, \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0436\u0435\u0439 \u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u043d\u0438\u043c\u0438 \u0438\u0434\u0438\u043e\u043c Rust \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0431\u0435\u0441\u0441\u043f\u043e\u0440\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u043a\u0430\u043a \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u0432 \u043d\u0430 Rust, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0442\u0435\u0445, \u0447\u0442\u043e \u0443\u0436\u0435 \u0443\u0441\u043f\u0435\u043b \u0441\u0435\u0431\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u043d\u043e \u0435\u0449\u0451 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043e\u0441\u0432\u043e\u0438\u043b\u0441\u044f \u0441 \u0431\u043e\u0433\u0430\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0442\u0438\u043f\u0430\u0436\u0435\u0439. \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u043e\u043f\u0435\u0447\u0430\u0442\u043e\u043a \u0432 \u043a\u043e\u0434\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430, \u043e\u0434\u043d\u0430\u043a\u043e \u0432 \u043e\u0431\u0449\u0435\u043c \u0438 \u0446\u0435\u043b\u043e\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0438 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435, \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u043e\u0434 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u00ab\u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u00bb, \u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u044e\u0442 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f.  <\/p>\n<hr\/>\n<p>  \u0412 \u043c\u043e\u0451\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c <a href=\"http:\/\/hermanradtke.com\/2015\/05\/03\/string-vs-str-in-rust-functions.html\">\u043f\u043e\u0441\u0442\u0435<\/a> \u043c\u044b \u043c\u043d\u043e\u0433\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>&#038;str<\/code> \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0445 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b. \u0411\u043b\u0438\u0436\u0435 \u043a \u043a\u043e\u043d\u0446\u0443 \u043f\u043e\u0441\u0442\u0430 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043b\u0438, \u043a\u043e\u0433\u0434\u0430 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>String<\/code>, \u0430 \u043a\u043e\u0433\u0434\u0430 <code>&#038;str<\/code> \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u0445 (<code>struct<\/code>). \u0425\u043e\u0442\u044f \u044f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u0441\u043e\u0432\u0435\u0442 \u0445\u043e\u0440\u043e\u0448, \u043d\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>&#038;str<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>String<\/code> \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e. \u0414\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433\u0430\u044f \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f.  <\/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-271528","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/271528","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=271528"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/271528\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=271528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=271528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=271528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}