{"id":324792,"date":"2021-06-11T15:00:48","date_gmt":"2021-06-11T15:00:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=324792"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=324792","title":{"rendered":"Rust \u2014 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u043e\u0431\u0431\u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0433\u0440\u0443\u0437\u0438\u0442\u044c\u0441\u044f \u0432 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 embedded \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Rust \u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043c\u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0435\u0431\u0435 \u043b\u043e\u0433\u0433\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0441\u0430\u043b \u043b\u043e\u0433\u0438 \u0447\u0435\u0440\u0435\u0437 <abbr title=\"Universal Asynchronous Receiver-Transmitter\">UART<\/abbr>, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0437\u043d\u0430\u043b \u043a\u0430\u043a\u0430\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f. \u0412\u043e\u0442 \u0442\u0443\u0442 \u044f \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043b, \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u0438 \u043c\u043e\u043d\u043e\u043c\u043e\u0440\u0444\u0438\u0437\u0430\u0446\u0438\u044e, \u0432\u0435\u0434\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u0443\u043c\u0435\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0442\u0438\u043f\u044b, \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0422\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0442\u0438\u043f&nbsp;<code>Box<\/code>, \u043d\u043e \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u0437 \u043a\u0443\u0447\u0438. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0438\u0434\u0435\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043d\u043e \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0431\u0443\u0444\u0435\u0440\u0435, \u0430 \u043d\u0435 \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u0443\u0447\u0435.<\/p>\n<p>\u0410 \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0432\u0437\u044f\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c&nbsp;<a href=\"https:\/\/crates.io\/crates\/linked_list_allocator\" rel=\"noopener noreferrer nofollow\">linked_list_allocator<\/a>&nbsp;\u043e\u0442 \u0424\u0438\u043b\u0430, \u0434\u0430\u0442\u044c \u0435\u043c\u0443 \u043f\u0430\u0440\u0443 \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c&nbsp;<code>Box<\/code>&nbsp;\u0442\u0438\u043f\u043e\u043c, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u0437\u044f\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 bump \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u0432\u0435\u0434\u044c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u043e \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u043a\u0443\u0447\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e? \u042d\u0442\u043e \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 \u0446\u0435\u043b\u043e\u0433\u043e&nbsp;<code>alloc<\/code>&nbsp;\u043a\u0440\u0435\u0439\u0442\u0430 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0438\u0441\u043a\u0438, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0443\u0447\u0438 \u0432\u044b\u0439\u0434\u0435\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u0441\u0442\u0440\u043e\u0433\u043e \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u0442\u0440\u0443\u0434\u043d\u043e\u0443\u043b\u043e\u0432\u0438\u043c\u044b\u043c \u043e\u0448\u0438\u0431\u043a\u0430\u043c.<\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c&nbsp;<code>&amp;'static dyn Trait<\/code>&nbsp;\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0435\u0440\u0435\u043b\u043e\u0436\u0438\u0442\u044c \u0437\u0430\u0431\u043e\u0442\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443, \u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043d\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0436\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f unsafe \u043a\u043e\u0434\u043e\u043c, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443. \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0438\u043b\u0438 \u0434\u0432\u043e\u0439\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0438\u043b\u0438 unsafe \u0432 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u043c API, \u0447\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043b\u043e\u0445\u043e. \u0414\u0430 \u0438 \u0432 \u0446\u0435\u043b\u043e\u043c, Box \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u0448\u0438\u0440\u043e\u043a\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0437\u0430\u0434\u0430\u0447 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u043c futures executor.<\/p>\n<h3>\u0427\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0435 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u0435 \u0442\u0438\u043f\u044b?<\/h3>\n<p>\u0425\u043e\u0447\u0443 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0442\u0438\u043f\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 (<abbr title=\"Dynamically Sized Types\">DST<\/abbr>) \u0438 \u0447\u0435\u043c \u043e\u043d\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0445. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0442\u0438\u043f\u043e\u0432 \u0438\u043c\u0435\u044e\u0442 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442 \u0442\u0440\u0435\u0439\u0442\u043e\u043c&nbsp;<code>Sized<\/code>, \u043d\u043e \u0435\u0441\u0442\u044c \u0442\u0438\u043f\u044b, \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0438\u0445 \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043b\u0438 \u043d\u0430 \u0441\u0442\u044d\u043a\u0435 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u0442\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u0435\u0449\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0422\u0443\u0442 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440&nbsp;<strong>\u0442\u043e\u0447\u043d\u043e<\/strong>&nbsp;\u0437\u043d\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0435\u0433\u043e \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0430, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u0439&nbsp;<code>dyn Display<\/code>&nbsp;\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0447\u0435\u043c \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c. \u0418 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u043c \u0442\u0438\u043f\u0430\u043c \u043b\u0438\u0448\u044c \u0441\u0441\u044b\u043b\u043a\u0438 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u0443\u0436 \u0440\u0430\u0437\u043c\u0435\u0440 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d.<\/p>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0432 Rust \u044d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 DST \u0442\u0438\u043f\u0430\u043c\u0438, \u043f\u043e\u043c\u0438\u043c\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0435\u0449\u0435 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u043d\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u044d\u0442\u043e \u0432\u0441\u0435 \u043e\u0441\u043e\u0437\u043d\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<pre><code class=\"rust\">#[repr(C)] pub(crate) union PtrRepr&lt;T: ?Sized&gt; {     pub(crate) const_ptr: *const T,     pub(crate) mut_ptr: *mut T,     pub(crate) components: PtrComponents&lt;T&gt;, }  #[repr(C)] pub(crate) struct PtrComponents&lt;T: ?Sized&gt; {     pub(crate) data_address: *const (),     pub(crate) metadata: &lt;T as Pointee&gt;::Metadata, }<\/code><\/pre>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0431\u0430\u0439\u0442\u044b \u0441 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u043b\u0435. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u043b\u044e\u0431\u044b\u043c, \u0432\u043e\u0442 \u0442\u0430\u043a, \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e&nbsp;<code>dyn Trait<\/code>&nbsp;&#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<pre><code class=\"rust\">pub struct DynMetadata&lt;Dyn: ?Sized&gt; {     vtable_ptr: &amp;'static VTable,     phantom: crate::marker::PhantomData&lt;Dyn&gt;, } \/\/\/ The common prefix of all vtables. It is followed by function pointers for trait methods. \/\/\/ \/\/\/ Private implementation detail of DynMetadata::size_of etc. #[repr(C)] struct VTable {     drop_in_place: fn(*mut ()),     size_of: usize,     align_of: usize, }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0440\u0430\u0437\u043c\u0435\u0440&nbsp;<code>&amp;dyn Display<\/code>&nbsp;\u043d\u0430 x86_64 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 16 \u0431\u0430\u0439\u0442, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"rust\">let a: u64 = 42; let dyn_a: &amp;dyn Display = &amp;a;<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442&nbsp;<code>VTable<\/code>&nbsp;\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u0433\u0434\u0435-\u0442\u043e \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u043d\u0430 \u0448\u0438\u0440\u043e\u043a\u0443\u044e, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u043a\u0440\u043e\u043c\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 \u0435\u0449\u0435 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0438 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u0435\u0441\u0442\u0430 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439&nbsp;<code>Box&lt;dyn Display&gt;<\/code>&nbsp;\u0438\u0437 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f&nbsp;<code>a<\/code>, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430&nbsp;<code>dyn_a<\/code>&nbsp;\u0438 \u0432\u0441\u0435 \u044d\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440. \u0427\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c nightly features:&nbsp;<a href=\"https:\/\/doc.rust-lang.org\/std\/marker\/trait.Unsize.html\" rel=\"noopener noreferrer nofollow\">unsize<\/a>&nbsp;\u0438&nbsp;<a href=\"https:\/\/doc.rust-lang.org\/std\/ptr\/fn.metadata.html\" rel=\"noopener noreferrer nofollow\">ptr_metadata<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f&nbsp;<code>&amp;dyn T<\/code>&nbsp;\u0438\u0437&nbsp;<code>&amp;Value<\/code>&nbsp;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0440\u043a\u0435\u0440\u043d\u044b\u0439 \u0442\u0440\u0435\u0439\u0442&nbsp;<code>Unsize<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443&nbsp;<code>Sized<\/code>&nbsp;\u0442\u0438\u043f\u043e\u043c \u0438 \u0435\u0433\u043e \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u043c \u0430\u043b\u044c\u0442\u0435\u0440-\u044d\u0433\u043e. \u0422\u043e \u0435\u0441\u0442\u044c,&nbsp;<code>T<\/code>&nbsp;\u044d\u0442\u043e&nbsp;<code>Unsize&lt;dyn Trait&gt;<\/code>&nbsp;\u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438&nbsp;<code>T<\/code>&nbsp;\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442&nbsp;<code>Trait<\/code>.<\/p>\n<p>\u0410 \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f&nbsp;<code>core::ptr::metadata<\/code>&nbsp;\u0438 \u0442\u0438\u043f\u0430\u0436&nbsp;<code>Pointee<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u0438\u043f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u0438 \u0442\u0438\u043f \u0435\u0433\u043e \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0442\u0438\u043f&nbsp;<code>DynMetadata&lt;T&gt;<\/code>, \u0433\u0434\u0435&nbsp;<code>T<\/code>&nbsp;\u044d\u0442\u043e \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u0439 \u0442\u0438\u043f.<\/p>\n<pre><code class=\"rust\">#[inline] fn meta_offset_layout&lt;T, Value&gt;(value: &amp;Value) -&gt; (DynMetadata&lt;T&gt;, Layout, usize) where     T: ?Sized + Pointee&lt;Metadata = DynMetadata&lt;T&gt;&gt;,     Value: Unsize&lt;T&gt; + ?Sized, {     \/\/ Get dynamic metadata for the given value.     let meta = ptr::metadata(value as &amp;T);     \/\/ Compute memory layout to store the value + its metadata.     let meta_layout = Layout::for_value(&amp;meta);     let value_layout = Layout::for_value(value);     let (layout, offset) = meta_layout.extend(value_layout).unwrap();     (meta, layout, offset) }<\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0435\u0449\u0435 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0435\u0449\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c.<\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u0431\u0435\u0440\u0435\u043c&nbsp;<\/em><code>Layout<\/code>&nbsp;\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u043d\u0435&nbsp;<code>DynMetadata&lt;Dyn&gt;::layout<\/code>, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435&nbsp;<code>VTable<\/code>, \u043d\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e&nbsp;<code>DynMetadata<\/code>, \u0431\u0443\u0434\u044c\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b!<\/p>\n<h3>\u041f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 Box<\/h3>\n<p>\u0412\u043e\u0442, \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448&nbsp;<code>Box<\/code>, \u0435\u0433\u043e \u043a\u043e\u0434 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439:<\/p>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0431\u0443\u0444\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e\u0435 API \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f.<\/p>\n<pre><code class=\"rust\">impl&lt;T, M&gt; Box&lt;T, M&gt; where     T: ?Sized + Pointee&lt;Metadata = DynMetadata&lt;T&gt;&gt;,     M: AsRef&lt;[u8]&gt; + AsMut&lt;[u8]&gt;, {     pub fn new_in_buf&lt;Value&gt;(mut mem: M, value: Value) -&gt; Self     where         Value: Unsize&lt;T&gt;,     {         let (meta, layout, offset) = meta_offset_layout(&amp;value);         \/\/ Check that the provided buffer has sufficient capacity to store the given value.         assert!(layout.size() &gt; 0);         assert!(layout.size() &lt;= mem.as_ref().len());          unsafe {             let ptr = NonNull::new(mem.as_mut().as_mut_ptr()).unwrap();             \/\/ Store dynamic metadata at the beginning of the given memory buffer.             ptr.cast::&lt;DynMetadata&lt;T&gt;&gt;().as_ptr().write(meta);             \/\/ Store the value in the remainder of the memory buffer.             ptr.cast::&lt;u8&gt;()                 .as_ptr()                 .add(offset)                 .cast::&lt;Value&gt;()                 .write(value);              Self {                 mem,                 phantom: PhantomData,             }         }     } }<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0438 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0431\u0430\u0439\u0442\u044b \u043d\u0430\u0437\u0430\u0434 \u0432&nbsp;<code>&amp;dyn Trait<\/code>:<\/p>\n<pre><code class=\"rust\">    #[inline]     fn meta(&amp;self) -&gt; DynMetadata&lt;T&gt; {         unsafe { *self.mem.as_ref().as_ptr().cast() }     }      #[inline]     fn layout_meta(&amp;self) -&gt; (Layout, usize, DynMetadata&lt;T&gt;) {         let meta = self.meta();         let (layout, offset) = Layout::for_value(&amp;meta).extend(meta.layout()).unwrap();         (layout, offset, meta)     }      #[inline]     fn value_ptr(&amp;self) -&gt; *const T {         let (_, offset, meta) = self.layout_meta();         unsafe {             let ptr = self.mem.as_ref().as_ptr().add(offset).cast::&lt;()&gt;();             ptr::from_raw_parts(ptr, meta)         }     }      #[inline]     fn value_mut_ptr(&amp;mut self) -&gt; *mut T {         let (_, offset, meta) = self.layout_meta();         unsafe {             let ptr = self.mem.as_mut().as_mut_ptr().add(offset).cast::&lt;()&gt;();             ptr::from_raw_parts_mut(ptr, meta)         }     }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u043c\u0435\u043b\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e&nbsp;<code>Deref<\/code>&nbsp;\u0438&nbsp;<code>DerefMut<\/code>, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044d\u0442\u0438 \u0441\u0430\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u0438 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b.<\/p>\n<pre><code class=\"rust\">impl&lt;T, M&gt; Deref for Box&lt;T, M&gt; where     T: ?Sized + Pointee&lt;Metadata = DynMetadata&lt;T&gt;&gt;,     M: AsRef&lt;[u8]&gt; + AsMut&lt;[u8]&gt;, {     type Target = T;      #[inline]     fn deref(&amp;self) -&gt; &amp;T {         self.as_ref()     } }  impl&lt;T, M&gt; DerefMut for Box&lt;T, M&gt; where     T: ?Sized + Pointee&lt;Metadata = DynMetadata&lt;T&gt;&gt;,     M: AsRef&lt;[u8]&gt; + AsMut&lt;[u8]&gt;, {     #[inline]     fn deref_mut(&amp;mut self) -&gt; &amp;mut T {         self.as_mut()     } }<\/code><\/pre>\n<pre><code>running 8 tests test tests::test_box_dyn_fn ... ok test tests::test_box_nested_dyn_fn ... ok test tests::test_box_in_provided_memory ... ok test tests::test_box_trait_object ... ok test tests::test_box_move ... ok test tests::test_drop ... ok test tests::test_layout_of_dyn ... ok test tests::test_box_insufficient_memory ... ok <\/code><\/pre>\n<h3>Miri<\/h3>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0432\u0441\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 \u0431\u043e\u0435\u0432\u043e\u043c \u043a\u043e\u0434\u0435&#8230; \u041d\u043e, \u043f\u043e\u0441\u0442\u043e\u0439\u0442\u0435, \u043c\u044b \u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 unsafe \u043a\u043e\u0434, \u043a\u0430\u043a \u043c\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u043e\u0436\u0435\u043c \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u044b \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0438\u043b\u0438 \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b? \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442, \u043a\u0430\u043a Miri, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 MIR, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c rustc, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u0448\u0438\u043d\u0443. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 unsafe \u043a\u043e\u0434\u0435, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0439&nbsp;<a href=\"https:\/\/habr.com\/en\/post\/460953\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Miri.<\/p>\n<pre><code>cargo miri test    Compiling static-box v0.0.1 (\/home\/aleksey\/Projects\/opensource\/static-box)     Finished test [unoptimized + debuginfo] target(s) in 0.40s      Running unittests (target\/x86_64-unknown-linux-gnu\/debug\/deps\/static_box-e2c02215f3157959) running 8 tests test tests::test_box_dyn_fn ... error: Undefined Behavior: accessing memory with alignment 1, but alignment 8 is required    --&gt; \/home\/aleksey\/.rustup\/toolchains\/nightly-2021-04-25-x86_64-unknown-linux-gnu\/lib\/rustlib\/src\/rust\/library\/core\/src\/ptr\/mod.rs:886:9     | 886 |         copy_nonoverlapping(&amp;src as *const T, dst, 1);     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory with alignment 1, but alignment 8 is required     |     = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior     = help: see https:\/\/doc.rust-lang.org\/nightly\/reference\/behavior-considered-undefined.html for further information <\/code><\/pre>\n<p>\u0410\u0433\u0430! \u0412\u043e\u0442 \u0438 \u043d\u0430\u0448\u043b\u0430\u0441\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0443\u043f\u0443\u0441\u0442\u0438\u043b\u0438, \u0438 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0430\u043c \u043d\u0430\u0448\u0430 x86 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u043b\u0430 \u0438 \u043f\u0440\u043e\u0441\u0442\u0438\u043b\u0430 &#8212; \u043d\u0435\u0432\u044b\u0440\u043e\u0432\u043d\u0435\u043d\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0430\u043c\u044f\u0442\u0438. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u044b \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430, \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0430\u0432\u0435\u043d \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0432 \u0442\u0438\u043f\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043a\u0440\u0430\u0442\u043d\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u0430\u0439\u0442\u044b \u0434\u043b\u044f \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f, \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0438 \u043f\u043e\u043b\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u0440\u044f\u0434 \u043f\u0438\u0448\u0435\u043c \u0431\u0430\u0439\u0442\u044b \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0431\u0443\u0444\u0435\u0440, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0430\u0434\u0440\u0435\u0441\u0430, \u043d\u0438\u043a\u0430\u043a \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u0430\u0434\u0440\u0435\u0441\u0430 \u043f\u043e\u043b\u0435\u0439 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043d\u0435 \u043a\u0440\u0430\u0442\u043d\u044b\u043c\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u043c\u0443 \u0441\u043b\u043e\u0432\u0443.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0447\u0438\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u043c \u0431\u0443\u0444\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044e, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0431\u0440\u0430\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0432\u044b\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c \u0431\u0443\u0444\u0435\u0440, \u043f\u0440\u0438\u0447\u0435\u043c \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u0433\u043e \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0431\u044b\u043b \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d \u043a\u0430\u043a \u043f\u043e\u043b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0431\u0443\u0444\u0435\u0440, \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043d\u0435\u0433\u043e, \u0430 \u043f\u043e\u0437\u0436\u0435 \u044d\u0442\u043e\u0442 \u0431\u0443\u0444\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d \u0432 \u0434\u0440\u0443\u0433\u0443\u044e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043d\u0430\u0448\u0435 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0435\u0440\u043d\u044b\u043c.<\/p>\n<pre><code class=\"rust\">        \/\/ Construct a box to move the specified memory into the necessary location.         \/\/ SAFETY: This code relies on the fact that this method will be inlined.         let mut new_box = Self {             align_offset: 0,             mem,             phantom: PhantomData,         };          let raw_ptr = new_box.mem.as_mut().as_mut_ptr();         \/\/ Compute the offset that needs to be applied to the pointer in order to make         \/\/ it aligned correctly.         new_box.align_offset = raw_ptr.align_offset(layout.align());<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u0432\u0441\u0435, \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e Miri \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code>cargo miri test    Compiling static-box v0.1.0 (\/home\/aleksey\/Projects\/opensource\/static-box)     Finished test [unoptimized + debuginfo] target(s) in 0.30s      Running unittests (target\/x86_64-unknown-linux-gnu\/debug\/deps\/static_box-ce23f69c165cf930)  running 11 tests test tests::test_box_dyn_fn ... ok test tests::test_box_in_provided_memory ... ok test tests::test_box_in_static_mem ... ok test tests::test_box_in_unaligned_memory ... ok test tests::test_box_insufficient_memory ... ok test tests::test_box_move ... ok test tests::test_box_nested_dyn_fn ... ok test tests::test_box_trait_object ... ok test tests::test_drop ... ok test tests::test_layout_of_dyn_split_at_mut ... ok test tests::test_layout_of_dyn_vec ... ok test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out    Doc-tests static-box running 2 tests test src\/lib.rs - (line 24) ... ok test src\/lib.rs - (line 48) ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.15s<\/code><\/pre>\n<p>\u0425\u043e\u0447\u0443 \u0435\u0449\u0435 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0432 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0438\u043f\u0430&nbsp;<code>Layout<\/code>, \u0432 \u043d\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0434\u0432\u0430 \u043f\u043e\u043b\u044f&nbsp;<code>size<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0431\u0430\u0439\u0442\u0430\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0438&nbsp;<code>align<\/code>&nbsp;&#8212; \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e (\u043f\u0440\u0438\u0447\u0435\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u0434\u0432\u043e\u0439\u043a\u0438), \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043a\u0440\u0430\u0442\u0435\u043d \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u0418 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0447\u0438\u043d\u0438\u0442\u044c \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u0430\u0434\u0440\u0435\u0441\u0443 \u043d\u0430\u0447\u0430\u043b\u0430 \u0431\u0443\u0444\u0435\u0440\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u0434\u0440\u0435\u0441 \u043a\u0440\u0430\u0442\u043d\u044b\u0439&nbsp;<code>align<\/code>. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043f\u0440\u043e \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435 \u0443&nbsp;<a href=\"https:\/\/os.phil-opp.com\/allocator-designs\/#address-alignment\" rel=\"noopener noreferrer nofollow\">\u0443 \u0424\u0438\u043b\u0430<\/a>.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0423\u0440\u0430, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u043a\u043e\u0434!<\/p>\n<pre><code class=\"rust\">use static_box::Box;  struct Uart1Rx {     \/\/ Implementation details... }  impl SerialWrite for Uart1Rx {     fn write(&amp;mut self, _byte: u8) {         \/\/ Implementation details     } } let rx = Uart1Rx { \/* ... *\/ };  SOME_GLOBAL_WRITER.init_once(move || Box::&lt;dyn SerialWrite, [u8; 32]&gt;::new(rx));  \/\/ A bit of code later.  SOME_GLOBAL_WRITER.lock().unwrap().write_str(\"Hello world!\"); <\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 unsafe \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 nightly \u0444\u0438\u0447 \u0441\u043c\u043e\u0433\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0438\u043f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0430 \u0441\u0442\u0435\u043a\u0435 \u0438\u043b\u0438 \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u0443\u0447\u0438, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445. \u0425\u043e\u0442\u044f, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0430\u0434\u0440\u0435\u0441 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u0432\u0437\u044f\u0442\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u044d\u0442\u0438 \u0430\u0434\u0440\u0435\u0441\u0430 \u043a\u0430\u043a \u043f\u043e\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 \u0441\u0430\u043c\u043e\u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0435\u0441\u044f, \u0447\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0432 Rust \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435, \u044d\u0442\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f. \u0412 \u0446\u0435\u043b\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f pin API, \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0448Box \u043d\u0435\u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c\u044b\u043c, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u044d\u0442\u0443 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e, \u0430 \u0437\u0430\u043e\u0434\u043d\u043e \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043b\u044e\u0431\u044b\u043c\u0438 Future \u0442\u0438\u043f\u0430\u043c\u0438.<\/p>\n<p>\u0425\u043e\u0447\u0443 \u0435\u0449\u0435 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a, \u0447\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0431\u043e\u044f\u0442\u044c\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 unsafe \u043a\u043e\u0434, \u043d\u043e \u0441\u0442\u043e\u0438\u0442 10 \u0440\u0430\u0437 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043d\u0430\u0434 \u0435\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Miri \u0432&nbsp;<a href=\"https:\/\/github.com\/alekseysidorov\/static-box\/blob\/master\/.github\/workflows\/ci.yml#L58\" rel=\"noopener noreferrer nofollow\">CI<\/a>&nbsp;\u0442\u0435\u0441\u0442\u0430\u0445, \u043e\u043d \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043e\u0448\u0438\u0431\u043e\u043a, \u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043a \u0434\u0435\u0442\u0430\u043b\u044f\u043c \u0432\u0441\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u043c \u0441\u043b\u0443\u0447\u0430\u044f\u043c. \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0441\u0447\u0435\u0442\u0435, \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u043d\u0430\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0442\u0430 \u0438\u043b\u0438 \u0438\u043d\u0430\u044f \u044f\u0437\u044b\u043a\u043e\u0432\u0430\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0442\u044c \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0435\u0451 \u043a\u0430\u043a \u0447\u0435\u0440\u043d\u0443\u044e \u043c\u0430\u0433\u0438\u044e. \u0427\u0430\u0441\u0442\u043e \u0432\u0441\u0435 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0435\u0435, \u0447\u0435\u043c \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043f\u043d\u0443\u0442\u044c \u0447\u0443\u0442\u044c \u043f\u043e\u0433\u043b\u0443\u0431\u0436\u0435.<\/p>\n<p>\u0410 \u0435\u0449\u0435 \u0432\u0430\u0436\u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0432\u044b\u0445\u043e\u0434\u0438\u0442\u044c \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 stable Rust, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u0432 \u043a\u0443\u0440\u0441\u0435, \u043a\u0443\u0434\u0430 \u0436\u0435 \u044f\u0437\u044b\u043a \u0434\u0430\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u0440\u0443\u0433\u043e\u0437\u043e\u0440.<\/p>\n<p><a href=\"https:\/\/crates.io\/crates\/static-box\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u0440\u0435\u0439\u0442<\/a><\/p>\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\/561012\/\"> https:\/\/habr.com\/ru\/post\/561012\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u043e\u0431\u0431\u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0433\u0440\u0443\u0437\u0438\u0442\u044c\u0441\u044f \u0432 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 embedded \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Rust \u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043c\u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0435\u0431\u0435 \u043b\u043e\u0433\u0433\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0438\u0441\u0430\u043b \u043b\u043e\u0433\u0438 \u0447\u0435\u0440\u0435\u0437 <abbr title=\"Universal Asynchronous Receiver-Transmitter\">UART<\/abbr>, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0437\u043d\u0430\u043b \u043a\u0430\u043a\u0430\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f. \u0412\u043e\u0442 \u0442\u0443\u0442 \u044f \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043b, \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u0438 \u043c\u043e\u043d\u043e\u043c\u043e\u0440\u0444\u0438\u0437\u0430\u0446\u0438\u044e, \u0432\u0435\u0434\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u043e\u0434 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u0443\u043c\u0435\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0442\u0438\u043f\u044b, \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0422\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0442\u0438\u043f&nbsp;<code>Box<\/code>, \u043d\u043e \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u0437 \u043a\u0443\u0447\u0438. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0430 \u0438\u0434\u0435\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0430\u043d\u0430\u043b\u043e\u0433 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043d\u043e \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0431\u0443\u0444\u0435\u0440\u0435, \u0430 \u043d\u0435 \u0432 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u0443\u0447\u0435.<\/p>\n<p>\u0410 \u043f\u043e\u0447\u0435\u043c\u0443 \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0432\u0437\u044f\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c&nbsp;<a href=\"https:\/\/crates.io\/crates\/linked_list_allocator\" rel=\"noopener noreferrer nofollow\">linked_list_allocator<\/a>&nbsp;\u043e\u0442 \u0424\u0438\u043b\u0430, \u0434\u0430\u0442\u044c \u0435\u043c\u0443 \u043f\u0430\u0440\u0443 \u043a\u0438\u043b\u043e\u0431\u0430\u0439\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c&nbsp;<code>Box<\/code>&nbsp;\u0442\u0438\u043f\u043e\u043c, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u0437\u044f\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 bump \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u0432\u0435\u0434\u044c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u043e \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u043a\u0443\u0447\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e? \u042d\u0442\u043e \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 \u0446\u0435\u043b\u043e\u0433\u043e&nbsp;<code>alloc<\/code>&nbsp;\u043a\u0440\u0435\u0439\u0442\u0430 \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0438\u0441\u043a\u0438, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0443\u0447\u0438 \u0432\u044b\u0439\u0434\u0435\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u0441\u0442\u0440\u043e\u0433\u043e \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u0442\u0440\u0443\u0434\u043d\u043e\u0443\u043b\u043e\u0432\u0438\u043c\u044b\u043c \u043e\u0448\u0438\u0431\u043a\u0430\u043c.<\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c&nbsp;<code>&amp;'static dyn Trait<\/code>&nbsp;\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0435\u0440\u0435\u043b\u043e\u0436\u0438\u0442\u044c \u0437\u0430\u0431\u043e\u0442\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443, \u043d\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043d\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0436\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f unsafe \u043a\u043e\u0434\u043e\u043c, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0442\u043e\u0436\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443. \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0438\u043b\u0438 \u0434\u0432\u043e\u0439\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0438\u043b\u0438 unsafe \u0432 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u043c API, \u0447\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043b\u043e\u0445\u043e. \u0414\u0430 \u0438 \u0432 \u0446\u0435\u043b\u043e\u043c, Box \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u0448\u0438\u0440\u043e\u043a\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0437\u0430\u0434\u0430\u0447 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u043c futures executor.<\/p>\n<h3>\u0427\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0435 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u0435 \u0442\u0438\u043f\u044b?<\/h3>\n<p>\u0425\u043e\u0447\u0443 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0442\u0438\u043f\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 (<abbr title=\"Dynamically Sized Types\">DST<\/abbr>) \u0438 \u0447\u0435\u043c \u043e\u043d\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0445. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0442\u0438\u043f\u043e\u0432 \u0438\u043c\u0435\u044e\u0442 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442 \u0442\u0440\u0435\u0439\u0442\u043e\u043c&nbsp;<code>Sized<\/code>, \u043d\u043e \u0435\u0441\u0442\u044c \u0442\u0438\u043f\u044b, \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0438\u0445 \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043b\u0438 \u043d\u0430 \u0441\u0442\u044d\u043a\u0435 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u0442\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u0435\u0449\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u043c\u0438.<\/p>\n<p>\u0422\u0443\u0442 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440&nbsp;<strong>\u0442\u043e\u0447\u043d\u043e<\/strong>&nbsp;\u0437\u043d\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0435\u0433\u043e \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0430, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u0439&nbsp;<code>dyn Display<\/code>&nbsp;\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0447\u0435\u043c \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c. \u0418 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u043c \u0442\u0438\u043f\u0430\u043c \u043b\u0438\u0448\u044c \u0441\u0441\u044b\u043b\u043a\u0438 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438, \u0443\u0436 \u0440\u0430\u0437\u043c\u0435\u0440 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d.<\/p>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0432 Rust \u044d\u0442\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 DST \u0442\u0438\u043f\u0430\u043c\u0438, \u043f\u043e\u043c\u0438\u043c\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0435\u0449\u0435 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u043d\u043e \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435 \u044d\u0442\u043e \u0432\u0441\u0435 \u043e\u0441\u043e\u0437\u043d\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438.<\/p>\n<pre><code class=\"rust\">#[repr(C)] pub(crate) union PtrRepr&lt;T: ?Sized&gt; {     pub(crate) const_ptr: *const T,     pub(crate) mut_ptr: *mut T,     pub(crate) components: PtrComponents&lt;T&gt;, }  #[repr(C)] pub(crate) struct PtrComponents&lt;T: ?Sized&gt; {     pub(crate) data_address: *const (),     pub(crate) metadata: &lt;T as Pointee&gt;::Metadata, }<\/code><\/pre>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0431\u0430\u0439\u0442\u044b \u0441 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u043b\u0435. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f, \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043e\u043e\u0431\u0449\u0435 \u043b\u044e\u0431\u044b\u043c, \u0432\u043e\u0442 \u0442\u0430\u043a, \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e&nbsp;<code>dyn Trait<\/code>&nbsp;&#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<pre><code class=\"rust\">pub struct DynMetadata&lt;Dyn: ?Sized&gt; {     vtable_ptr: &amp;'static VTable,     phantom: crate::marker::PhantomData&lt;Dyn&gt;, } \/\/\/ The common prefix of all vtables. It is followed by function pointers for trait methods. \/\/\/ \/\/\/ Private implementation detail of DynMetadata::size_of etc. #[repr(C)] struct VTable {     drop_in_place: fn(*mut ()),     size_of: usize,     align_of: usize, }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0440\u0430\u0437\u043c\u0435\u0440&nbsp;<code>&amp;dyn Display<\/code>&nbsp;\u043d\u0430 x86_64 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 16 \u0431\u0430\u0439\u0442, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0432\u043e\u0442 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"rust\">let a: u64 = 42; let dyn_a: &amp;dyn Display = &amp;a;<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442&nbsp;<code>VTable<\/code>&nbsp;\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u0433\u0434\u0435-\u0442\u043e \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u043d\u0430 \u0448\u0438\u0440\u043e\u043a\u0443\u044e, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u043a\u0440\u043e\u043c\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 \u0435\u0449\u0435 \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0438 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043c\u0435\u0441\u0442\u0430 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0436\u0435\u043b\u0430\u0435\u043c\u044b\u0439&nbsp;<code>Box&lt;dyn Display&gt;<\/code>&nbsp;\u0438\u0437 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f&nbsp;<code>a<\/code>, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430&nbsp;<code>dyn_a<\/code>&nbsp;\u0438 \u0432\u0441\u0435 \u044d\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440. \u0427\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c nightly features:&nbsp;<a href=\"https:\/\/doc.rust-lang.org\/std\/marker\/trait.Unsize.html\" rel=\"noopener noreferrer nofollow\">unsize<\/a>&nbsp;\u0438&nbsp;<a href=\"https:\/\/doc.rust-lang.org\/std\/ptr\/fn.metadata.html\" rel=\"noopener noreferrer nofollow\">ptr_metadata<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f&nbsp;<code>&amp;dyn T<\/code>&nbsp;\u0438\u0437&nbsp;<code>&amp;Value<\/code>&nbsp;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0440\u043a\u0435\u0440\u043d\u044b\u0439 \u0442\u0440\u0435\u0439\u0442&nbsp;<code>Unsize<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443&nbsp;<code>Sized<\/code>&nbsp;\u0442\u0438\u043f\u043e\u043c \u0438 \u0435\u0433\u043e \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u043c \u0430\u043b\u044c\u0442\u0435\u0440-\u044d\u0433\u043e. \u0422\u043e \u0435\u0441\u0442\u044c,&nbsp;<code>T<\/code>&nbsp;\u044d\u0442\u043e&nbsp;<code>Unsize&lt;dyn Trait&gt;<\/code>&nbsp;\u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438&nbsp;<code>T<\/code>&nbsp;\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442&nbsp;<code>Trait<\/code>.<\/p>\n<p>\u0410 \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f&nbsp;<code>core::ptr::metadata<\/code>&nbsp;\u0438 \u0442\u0438\u043f\u0430\u0436&nbsp;<code>Pointee<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u0438\u043f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u0438 \u0442\u0438\u043f \u0435\u0433\u043e \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0442\u0438\u043f&nbsp;<code>DynMetadata&lt;T&gt;<\/code>, \u0433\u0434\u0435&nbsp;<code>T<\/code>&nbsp;\u044d\u0442\u043e \u0438\u0441\u043a\u043e\u043c\u044b\u0439 \u0431\u0435\u0437\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u044b\u0439 \u0442\u0438\u043f.<\/p>\n<pre><code class=\"rust\">#[inline] fn meta_offset_layout&lt;T, Value&gt;(value: &amp;Value) -&gt; (DynMetadata&lt;T&gt;, Layout, usize) where     T: ?Sized + Pointee&lt;Metadata = DynMetadata&lt;T&gt;&gt;,     Value: Unsize&lt;T&gt; + ?Sized, {     \/\/ Get dynamic metadata for the given value.     let meta = ptr::metadata(value as &amp;T);     \/\/ Compute memory layout to store the value + its metadata.     let meta_layout = Layout::for_value(&amp;meta);     let value_layout = Layout::for_value(value);     let (layout, offset) = meta_layout.extend(value_layout).unwrap();     (meta, layout, offset) }<\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0435\u0449\u0435 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0435\u0449\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c.<\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u0431\u0435\u0440\u0435\u043c&nbsp;<\/em><code>Layout<\/code>&nbsp;\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u043d\u0435&nbsp;<code>DynMetadata&lt;Dyn&gt;::layout<\/code>, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435&nbsp;<code>VTable<\/code>, \u043d\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e&nbsp;<code>DynMetadata<\/code>, \u0431\u0443\u0434\u044c\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b!<\/p>\n<h3>\u041f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 Box<\/h3>\n<p>\u0412\u043e\u0442, \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448&nbsp;<code>Box<\/code>, \u0435\u0433\u043e \u043a\u043e\u0434 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439:<\/p>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0431\u0443\u0444\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e\u0435 API \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f.<\/p>\n<pre><code class=\"rust\">impl&lt;T, M&gt; Box&lt;T, M&gt; where     T: ?Sized + Pointee&lt;Metadata = DynMetadata&lt;T&gt;&gt;,     M: AsRef&lt;[u8]&gt; + AsMut&lt;[u8]&gt;, {     pub fn new_in_buf&lt;Value&gt;(mut mem: M, value: Value) -&gt; Self     where         Value: Unsize&lt;T&gt;,     {         let (meta, layout, offset) = meta_offset_layout(&amp;value);         \/\/ Check that the provided buffer has sufficient capacity to store the given value.         assert!(layout.size() &gt; 0);         assert!(layout.size() &lt;= mem.as_ref().len());          unsafe {             let ptr = NonNull::new(mem.as_mut().as_mut_ptr()).unwrap();             \/\/ Store dynamic metadata at the beginning of the given memory buffer.             ptr.cast::&lt;DynMetadata&lt;T&gt;&gt;().as_ptr().write(meta);             \/\/ Store the value in the remainder of the memory buffer.             ptr.cast::&lt;u8&gt;()                 .as_ptr()                 .add(offset)                 .cast::&lt;Value&gt;()                 .write(value);              Self {                 mem,                 phantom: PhantomData,             }         }     } }<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0438 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0431\u0430\u0439\u0442\u044b \u043d\u0430\u0437\u0430\u0434 \u0432&nbsp;<code>&amp;dyn Trait<\/code>:<\/p>\n<pre><code class=\"rust\">    #[inline]     fn meta(&amp;self) -&gt; DynMetadata&lt;T&gt; {         unsafe { *self.mem.as_ref().as_ptr().cast() }     }      #[inline]     fn layout_meta(&amp;self) -&gt; (Layout, usize, DynMetadata&lt;T&gt;) {         let meta = self.meta();         let (layout, offset) = Layout::for_value(&amp;meta).extend(meta.layout()).unwrap();         (layout, offset, meta)     }      #[inline]     fn value_ptr(&amp;self) -&gt; *const T {         let (_, offset, meta) = self.layout_meta();         unsafe {             let ptr = self.mem.as_ref().as_ptr().add(offset).cast::&lt;()&gt;();             ptr::from_raw_parts(ptr, meta)         }     }      #[inline]     fn value_mut_ptr(&amp;mut self) -&gt; *mut T {         let (_, offset, meta) = self.layout_meta();         unsafe {             let ptr = self.mem.as_mut().as_mut_ptr().add(offset).cast::&lt;()&gt;();             ptr::from_raw_parts_mut(ptr, meta)         }     }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u043c\u0435\u043b\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e&nbsp;<code>Deref<\/code>&nbsp;\u0438&nbsp;<code>DerefMut<\/code>, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044d\u0442\u0438 \u0441\u0430\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u0438 \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b.<\/p>\n<pre><code class=\"rust\">impl&lt;T, M&gt; Deref for Box&lt;T, M&gt; where     T: ?Sized + Pointee&lt;Metadata = DynMetadata&lt;T&gt;&gt;,     M: AsRef&lt;[u8]&gt; + AsMut&lt;[u8]&gt;, {     type Target = T;      #[inline]     fn deref(&amp;self) -&gt; &amp;T {         self.as_ref()     } }  impl&lt;T, M&gt; DerefMut for Box&lt;T, M&gt; where     T: ?Sized + Pointee&lt;Metadata = DynMetadata&lt;T&gt;&gt;,     M: AsRef&lt;[u8]&gt; + AsMut&lt;[u8]&gt;, {     #[inline]     fn deref_mut(&amp;mut self) -&gt; &amp;mut T {         self.as_mut()     } }<\/code><\/pre>\n<pre><code>running 8 tests test tests::test_box_dyn_fn ... ok test tests::test_box_nested_dyn_fn ... ok test tests::test_box_in_provided_memory ... ok test tests::test_box_trait_object ... ok test tests::test_box_move ... ok test tests::test_drop ... ok test tests::test_layout_of_dyn ... ok test tests::test_box_insufficient_memory ... ok <\/code><\/pre>\n<h3>Miri<\/h3>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0432\u0441\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432 \u0431\u043e\u0435\u0432\u043e\u043c \u043a\u043e\u0434\u0435&#8230; \u041d\u043e, \u043f\u043e\u0441\u0442\u043e\u0439\u0442\u0435, \u043c\u044b \u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 unsafe \u043a\u043e\u0434, \u043a\u0430\u043a \u043c\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u043c\u043e\u0436\u0435\u043c \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u044b \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0438\u043b\u0438 \u043d\u0438\u043a\u0430\u043a\u0438\u0435 \u0438\u043d\u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b? \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442, \u043a\u0430\u043a Miri, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 MIR, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c rustc, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u0448\u0438\u043d\u0443. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 unsafe \u043a\u043e\u0434\u0435, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0439&nbsp;<a href=\"https:\/\/habr.com\/en\/post\/460953\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Miri.<\/p>\n<pre><code>cargo miri test <\/code><\/pre>\n<\/div>\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-324792","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324792","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=324792"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324792\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}