The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]



"Выпуск языка программирования Rust 1.54"
Версия для распечатки Пред. тема | След. тема
Форум Разговоры, обсуждение новостей
Исходное сообщение [ Отслеживать ]
Отдельный RSS теперь доступен для каждого обсуждения в форуме и каждого минипортала.
. "Выпуск языка программирования Rust 1.54" +/
Сообщение от Аноним (-), 30-Июл-21, 14:41 
> Еще можно глянуть пример PhantomData как частный вариант ZST.
> https://doc.rust-lang.org/stable/core/marker/struct.PhantomD...

Я бы дал ссылку на
https://doc.rust-lang.org/nomicon/phantom-data.html

> PhantomData consumes no space, but simulates a field of the given type for the purpose of static analysis. This was deemed to be less error-prone than explicitly telling the type-system the kind of variance that you want, while also providing other useful things such as the information needed by drop check.

там и пример для ZST более лаконичен и поняте не-рустовцам
https://doc.rust-lang.org/nomicon/exotic-sizes.html
> On their own, Zero Sized Types (ZSTs) are, for obvious reasons, pretty useless.

...
> One of the most extreme examples of this is Sets and Maps. Given a Map<Key, Value>, it is common to implement a Set<Key> as just a thin wrapper around Map<Key, UselessJunk>. In many languages, this would necessitate allocating space for UselessJunk and doing work to store and load UselessJunk only to discard it. Proving this unnecessary would be a difficult analysis for the compiler.
> However in Rust, we can just say that Set<Key> = Map<Key, ()>. Now Rust statically knows that every load and store is useless, and no allocation has any size. The result is that the monomorphized code is basically a custom implementation of a HashSet with none of the overhead that HashMap would have to support values.

Ответить | Правка | Наверх | Cообщить модератору

Оглавление
Выпуск языка программирования Rust 1.54, opennews, 29-Июл-21, 22:11  [смотреть все]
Форумы | Темы | Пред. тема | След. тема



Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру