Are rust references (usually) types of Voldemort?

Voldemort - one who should not be called - types - these are types whose names cannot be written in the source code. In Rust, closures have these types because the compiler generates a new inner type for each closure . The only way to accept closure as an argument to a function is to accept a generic type (usually called F ), which is bounded as an Fn() (or similar) attribute.

Links in Rust always contain a lifetime parameter, even though this lifetime can usually be omitted. Lifetime cannot be called explicitly because they represent some complex internal area of ​​the compiler. The only way to interact with the lifetime is to use a common parameter (usually called 'a ), which refers to any lifetime (possibly limited by another lifetime). Of course, there is a 'static that can be called, but this is a special case and does not contradict my arguments.

So: are rust links Voldemort types? Or am I misunderstanding the term “Voldemort type” or rust references?

+6
source share
1 answer

As a person who does not have particularly strong knowledge in this area:

I think the answer is probably: technically yes, but it is too reductive. A bit like saying "all types are arrays of integers"; I mean, yes, but you are losing some useful semantic discrimination by doing this.

Voldemort types usually hide the implementation type from the user either because it only needs to be temporary, or you should not use anything other than the interface described by the function. Links are technically non-flammable in their entirety, but it’s not as if it really limits you. I mean, even if you could name a specific life expectancy, I don’t think that you could do anything meaningful with it (except, perhaps, for a more rigorous check of the lifetime in a function).

+4
source

Source: https://habr.com/ru/post/1011628/


All Articles