rust-tropes | tropes around the community of Rust developers | Dictionary library
kandi X-RAY | rust-tropes Summary
kandi X-RAY | rust-tropes Summary
This project is an initiative to write a dictionary of expressions and other jargon used by members of the Rust community.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of rust-tropes
rust-tropes Key Features
rust-tropes Examples and Code Snippets
Community Discussions
Trending Discussions on rust-tropes
QUESTION
The implementation of std::mem::drop
is documented to be the following:
ANSWER
Answered 2019-Nov-29 at 08:38The core of the issue is that drop
is not a single function, but rather a parameterized set of functions that each drop some particular type. To satisfy a higher-ranked trait bound (hereafter hrtb), you'd need a single function that can simultaneously take references to a type with any given lifetime.
We'll use drop
as our typical example of a generic function, but all this applies more generally too. Here's the code for reference: fn drop(_: T) {}
.
Conceptually, drop
is not a single function, but rather one function for every possible type T
. Any particular instance of drop
takes only arguments of a single type. This is called monomorphization. If a different T
is used with drop
, a different version of drop
is compiled. That's why you can't pass a generic function as an argument and use that function in full generality (see this question)
On the other hand, a function like fn pass(x: &i32) -> &i32 {x}
satisfies the hrtb for<'a> Fn(&'a i32) -> &'a i32
. Unlike drop
, we have a single function that simultaneously satisfies Fn(&'a i32) -> &'a i32
for every lifetime 'a
. This is reflected in how pass
can be used.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install rust-tropes
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page