{"id":384894,"date":"2024-06-29T05:47:22","date_gmt":"2024-06-29T05:47:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=384894"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T05:47:22","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=384894","title":{"rendered":"<span>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u0443\u0447\u0435\u0439 \u0432 Rust<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0438\u0437\u0443\u0447\u0430\u0442\u044c Rust \u043d\u0435\u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u044e\u0430\u043d\u0441\u0430\u0445 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u0443\u0447\u0435\u0439, \u0434\u043b\u044f \u0438\u0445 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f <a href=\"https:\/\/www.youtube.com\/watch?v=sq9UsgHzHmc&amp;t=137s\" rel=\"nofollow noopener noreferrer\">\u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f<\/a>: \u0441\u044b\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u0443\u0447\u0435, \u0440\u0430\u0437\u043c\u0435\u0440 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0438\u043f\u0430, \u0437\u0430\u043f\u0438\u0441\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u043a\u0443\u0447\u0443 \u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u043d\u0435\u0435, const \u0438 static, unit-like \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e, overkill \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0430 \u0432\u043e\u0442 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0432\u043e\u0438\u0442\u044c.<\/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\/569496\/\">\u0412\u0440\u0435\u043c\u0435\u043d\u0430 \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/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=\"syrye-ukazateli-raw-pointers\">\u0421\u044b\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 (Raw Pointers)<\/h1>\n<p>  <\/p>\n<p><a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=3e4bd22edbccd44f845b844913b03b59\" rel=\"nofollow noopener noreferrer\">\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">    let i: i32 = 10;     let pi = &amp;i as *const i32;     unsafe {         dbg!(*pi);     }<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7aa0a710c8d01ed76d7c250e456a1fa9\" rel=\"nofollow noopener noreferrer\">\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">    let mut i: i32 = 10;     let p_i = &amp;mut i as *mut i32;     unsafe {         *p_i = 20;         println!(\"*p_i: {}\", *p_i)     }<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b6df6e350d33cd634723023a67e3a02d\" rel=\"nofollow noopener noreferrer\">\u041f\u0440\u043e\u0442\u0438\u0432 \u043f\u0440\u0430\u0432\u0438\u043b<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">    let i: i32 = 0x_10_20_30_40;         let p_i = &amp;i as *const _ as *mut i16;     unsafe{          *p_i = 0x_70_80;          *p_i.offset(1) = 0x_50_60;     }     println!(\"i: {:x}\", i);<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u0411\u0440\u0430\u0442\u044c \u0430\u0434\u0440\u0435\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e, \u0430 \u0432\u043e\u0442 \u0440\u0430\u0437\u044b\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u2014 \u043e\u043f\u0430\u0441\u043d\u0430\u044f \u0437\u0430\u0442\u0435\u044f, \u0442\u0430\u043a \u0447\u0442\u043e \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0442\u0435\u0440\u0440\u0438\u0442\u043e\u0440\u0438\u044e <code>unsafe{}<\/code><\/li>\n<li>\u0414\u043b\u044f \u0440\u044f\u0434\u0430 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0438 \u0438\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u0441 \u043d\u0435\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u044c\u044e, \u043d\u0430\u0434\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/doc.rust-lang.org\/core\/ptr\/macro.addr_of.html\" rel=\"nofollow noopener noreferrer\">ptr::addr_of!()<\/a> \/ <a href=\"https:\/\/doc.rust-lang.org\/core\/ptr\/macro.addr_of_mut.html\" rel=\"nofollow noopener noreferrer\">ptr::addr_of_mut!()<\/a><\/li>\n<li>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u0441\u044b\u0440\u044b\u0445 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439: <a href=\"https:\/\/doc.rust-lang.org\/std\/primitive.pointer.html\" rel=\"nofollow noopener noreferrer\">primitive.pointer<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<h1 id=\"vydelenie-i-osvobozhdenie-pamyati\">\u0412\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438<\/h1>\n<p>  <\/p>\n<p><a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=d18941594c0f02e46830fa1e7b5b5bc5\" rel=\"nofollow noopener noreferrer\">\u0427\u0435\u0440\u0435\u0437 std::alloc::alloc(), std::alloc::dealloc()<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] struct Point {     x: i32,     y: i32, }  fn main(){     let ppoint = alloc_t::&lt;Point>();      unsafe {         (*ppoint).x = 10;         (*ppoint).y = 20;         println!(\"*ppoint: {:?}\", *ppoint);     }      dealloc_t(ppoint); } fn alloc_t&lt;T> () -> * mut T{     let layout = std::alloc::Layout::new::&lt;T>();     unsafe {         let res = std::alloc::alloc(layout) as *mut T;         if res.is_null() {             std::alloc::handle_alloc_error(layout);         }         return res;     } } fn dealloc_t&lt;T> (p: *mut T) {     let layout = std::alloc::Layout::new::&lt;T>();     unsafe {         std::alloc::dealloc(p as *mut u8, layout);     } }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0430\u0440\u0430 alloc()\/dealloc() \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0432 The Rustonomicon <a href=\"https:\/\/doc.rust-lang.org\/nomicon\/vec-raw.html\" rel=\"nofollow noopener noreferrer\"><code>\u043f\u0440\u0438 \u0440\u0430\u0437\u0431\u043e\u0440\u0435 RawVec<\/code><\/a><\/li>\n<li>Nomicon <a href=\"https:\/\/github.com\/rust-lang\/rust\/blob\/eaf6f463599df1f18da94a6965e216ea15795417\/library\/alloc\/src\/raw_vec.rs\" rel=\"nofollow noopener noreferrer\">\u0442\u043e \u043b\u0438 \u043e\u0442\u0441\u0442\u0430\u0435\u0442, \u0442\u043e \u043b\u0438 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442<\/a> (\u0432 \u0441\u043c\u044b\u0441\u043b\u0435, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u043f\u0430\u0440\u0430 \u0443\u0436\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f)<\/li>\n<li>\u041a\u0430\u043a \u043e\u0431\u0441\u0442\u043e\u044f\u0442 \u0434\u0435\u043b\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0441 <code>RawVec<\/code>, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0437\u0436\u0435, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u044b \u043d\u0435\u0432\u0435\u0434\u043e\u043c\u044b\u0435 \u043f\u043e\u043a\u0430 (\u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439) \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u044f\u0437\u044b\u043a\u0430<\/li>\n<li>\u0412\u044b\u0437\u043e\u0432 <code>handle_alloc_error<\/code> \u2014 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 (&#171;&#8230;are encouraged to call this function&#187;) \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438<\/li>\n<li><code>handle_alloc_error()<\/code> \u0438\u043c\u0435\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443 <code>pub fn handle_alloc_error(layout: Layout) -> !<\/code> \u2014 &#171;\u0444\u0430\u0442\u0430\u043b\u044c\u043d\u0430\u044f&#187; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0421\u043c. \u0442\u0430\u043a\u0436\u0435:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=8316f4d7622e22b5c7945d83562ab83f\" rel=\"nofollow noopener noreferrer\">\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 malloc<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<h1 id=\"razmer-ekzemplyara-tipa\">\u0420\u0430\u0437\u043c\u0435\u0440 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0438\u043f\u0430<\/h1>\n<p>  <\/p>\n<p>\u041d\u0430\u0443\u0447\u0438\u0432\u0448\u0438\u0441\u044c \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u043d\u0430 \u0447\u0442\u043e \u043e\u043d\u0430 \u043f\u043e\u0439\u0434\u0435\u0442. \u041f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u0442\u0438\u043f\u044b \u0431\u044b\u0432\u0430\u044e\u0442:<\/p>\n<p>  <\/p>\n<p><strong>1. Sized Types<\/strong>. \u0418\u0445 \u0440\u0430\u0437\u043c\u0435\u0440 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u0438\u043f\u0430. <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=98be288fb2a8e9cc9bbebdff00403251\" rel=\"nofollow noopener noreferrer\">\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432, \u0433\u0434\u0435 \u0440\u0430\u0437\u043c\u0435\u0440 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0443\u043b\u044f<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">...     dbg!(mem::size_of::&lt;bool>());     dbg!(mem::align_of::&lt;bool>());     dbg!(mem::size_of::&lt;[i32; 50]>());     dbg!(mem::align_of::&lt;[i32; 50]>());     dbg!(mem::size_of::&lt;PointTuple>());     dbg!(mem::align_of::&lt;PointTuple>()); ...    <\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0440\u0430 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u0441\u043b\u043e\u0432 \u043f\u0440\u043e \u043a\u043e\u0440\u0442\u0435\u0436 (tuple). \u042d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441 <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=e92bfe9b7640b12271140fc200cb5bf6\" rel=\"nofollow noopener noreferrer\">\u0431\u0435\u0437\u044b\u043c\u044f\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[derive(Debug)] struct PointTuple(i32, i32);  fn main() {     let mut pt = PointTuple(10, 20);     pt.0 = 100;     pt.1 = 200;     dbg!(pt); }<\/code><\/pre>\n<p>  <\/p>\n<p><strong>2. Zero Sized Types (ZST)<\/strong>. \u041f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e Sized, \u0440\u0430\u0437\u043c\u0435\u0440 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0438\u043f\u0430 \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e, \u043d\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=7cf8effd5b4ad75d0c96736b9c04048c\" rel=\"nofollow noopener noreferrer\">\u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041a ZST \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041f\u0443\u0441\u0442\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/li>\n<li>Unit-like \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/li>\n<li>\u041f\u0443\u0441\u0442\u044b\u0435 \u043a\u043e\u0440\u0442\u0435\u0436\u0438<\/li>\n<li>\u041f\u0443\u0441\u0442\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b<\/li>\n<\/ul>\n<p>  <\/p>\n<blockquote><p>!!! <strong>\u041f\u043e\u0434\u0430\u0432\u0430\u0442\u044c layout \u0442\u0430\u043a\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u043b\u044c\u0437\u044f<\/strong> <\/p><\/blockquote>\n<p>\u041d\u0443 \u0442.\u0435. \u043c\u043e\u0436\u043d\u043e, \u043d\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 undefined behavior.<\/p>\n<p>  <\/p>\n<p><strong>3. Empty Types<\/strong>. \u042d\u043a\u0437\u043e\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0442\u0438\u043f\u044b, \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u041f\u0443\u0441\u0442\u043e\u0439 <code>enum<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">enum ZeroVariants {}<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/doc.rust-lang.org\/reference\/types\/never.html\" rel=\"nofollow noopener noreferrer\"><code>NeverType<\/code><\/a> (\u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0442\u0438\u043f \u043d\u0435 &#171;\u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d&#187;):<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">let x: ! = panic!();<\/code><\/pre>\n<p>  <\/p>\n<p><strong>4. Dynamically Sized Types (DSTs)<\/strong>. \u0420\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u043a\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b (traits);<\/li>\n<li>\u0441\u0440\u0435\u0437\u044b (slices): [T], str.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>Rust \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u0442 \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">let s1: str = \"Hello there!\";<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u2014 \u043f\u043e\u0447\u0435\u043c\u0443, \u0432\u0435\u0434\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f &#171;Hello there!&#187;? \u0415\u0441\u0442\u044c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <strong>\u0432\u0441\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b Sized-\u0442\u0438\u043f\u0430 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440<\/strong>, \u0432\u043e\u0442 \u0435\u043c\u0443-\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f str \u0438 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 (\u0442.\u0435. \u0435\u0434\u0438\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043d\u0435\u0442), \u0442\u0430\u043a \u0447\u0442\u043e \u2014 <code>&amp;str<\/code> \u0438 DST.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0435\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0441\u043c.:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/doc.rust-lang.org\/nomicon\/exotic-sizes.html#exotically-sized-types\" rel=\"nofollow noopener noreferrer\">The Rustonomicon::Exotically Sized Types<\/a><\/li>\n<li><a href=\"https:\/\/doc.rust-lang.org\/reference\/type-layout.html\" rel=\"nofollow noopener noreferrer\">The Rust Reference::Type Layout<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<h1 id=\"zapis--chtenie\">\u0417\u0430\u043f\u0438\u0441\u044c \/ \u0447\u0442\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u0421\u0443\u043c\u0440\u0430\u043a \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0422\u0443\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">    let ppoint = alloc_t::&lt;Point>();      \/\/ Write to heap     {         let p = Point{x: 101, y:201};         unsafe {ppoint.write(p)}         println!(\"ppoint.write() completed\");     }<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><strong>\u0412\u0430\u0436\u043d\u043e<\/strong>: \u0414\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0434\u043b\u044f <code>p<\/code> \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u041d\u0415 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0442.\u0435. Rust \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u0430\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u0430\u043a \u0431\u044b &#171;\u0437\u0430\u0431\u044b\u0432\u0430\u0435\u0442&#187; \u043f\u0440\u043e \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e (\u0442\u0435\u043a\u0443\u0449\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c: <a href=\"https:\/\/github.com\/rust-lang\/rust\/blob\/20e92344bc46011de7d8deda2fb49c54ed2a6435\/library\/core\/src\/ptr\/mut_ptr.rs#L1008\" rel=\"nofollow noopener noreferrer\">\u0440\u0430\u0437<\/a>, <a href=\"https:\/\/github.com\/rust-lang\/rust\/blob\/20e92344bc46011de7d8deda2fb49c54ed2a6435\/library\/core\/src\/ptr\/mod.rs#L882\" rel=\"nofollow noopener noreferrer\">\u0434\u0432\u0430<\/a>).<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">    \/\/ Read from heap     {         let p;         unsafe { p = ppoint.read()}         println!(\"ppoint.read() completed: {:?}\", p);     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0436\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c <code>Drop<\/code> \u0434\u043b\u044f <code>Point<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Drop for Point {     fn drop(&amp;mut self) {         println!(\"Point dropped: {:?}\", self);     } }<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/play.rust-lang.org\/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=d27db558afbf73c89b9add5f981c09ec\" rel=\"nofollow noopener noreferrer\">\u0412\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435<\/a> \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0434\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">ppoint.write() completed ppoint.read() completed: Point { x: 101, y: 201 } Point dropped: Point { x: 101, y: 201 }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422.\u0435. \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c, \u0437\u0430\u0442\u0435\u043c \u0447\u0438\u0442\u0430\u0435\u043c, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0443 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/youtu.be\/7zQIeOTe020?t=167s\" rel=\"nofollow noopener noreferrer\">\u0415\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e<\/a> \u2014 \u0438 \u0441 \u043a\u0443\u0447\u0435\u0439 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043c.<\/p>\n<p>  <\/p>\n<p><strong>\u0414\u0430\u043b\u0435\u0435<\/strong>: <a href=\"https:\/\/habr.com\/ru\/post\/574522\/\">\u0417\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440<\/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\/573422\/\"> https:\/\/habr.com\/ru\/articles\/573422\/<\/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 \u0438\u0437\u0443\u0447\u0430\u0442\u044c Rust \u043d\u0435\u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u044e\u0430\u043d\u0441\u0430\u0445 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u0443\u0447\u0435\u0439, \u0434\u043b\u044f \u0438\u0445 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f <a href=\"https:\/\/www.youtube.com\/watch?v=sq9UsgHzHmc&amp;t=137s\" rel=\"nofollow noopener noreferrer\">\u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f<\/a>: \u0441\u044b\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u0443\u0447\u0435, \u0440\u0430\u0437\u043c\u0435\u0440 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0438\u043f\u0430, \u0437\u0430\u043f\u0438\u0441\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u043a\u0443\u0447\u0443 \u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u043d\u0435\u0435, const \u0438 static, unit-like \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e, overkill \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u0430 \u0432\u043e\u0442 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0432\u043e\u0438\u0442\u044c.<\/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\/569496\/\">\u0412\u0440\u0435\u043c\u0435\u043d\u0430 \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/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-384894","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/384894","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=384894"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/384894\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=384894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=384894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=384894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}