Re:Rust means never having to close a socket
by rcthompson on Tuesday October 07, 2014 @01:08PM
(#8422375)
So in the first example, "from_file" is never used after the first call to "io::util::copy". Is Rust smart enough to realize that this is the last use of "from_file" and release it right then, or does it wait until it goes out of scope at the end of the function?
[ Parent
| on HN ]
Re:Rust means never having to close a socket
by zokier on Tuesday October 07, 2014 @01:15PM
(#8422427)
There is ongoing discussion about this, eg here: https://github.com/rust-lang/rfcs/pull/239 (related reddit thread: http://www.reddit.com/r/rust/comments/2gs85u/rfc_allow_compi... )
Re:Rust means never having to close a socket
by steveklabnik on Tuesday October 07, 2014 @01:13PM
(#8422413)
Currently, borrows are lexical. We don't want them to be that way forever. https://github.com/rust-lang/rust/issues/6393
Re:Rust means never having to close a socket
by wycats on Tuesday October 07, 2014 @01:16PM
(#8422436)
To be more specific, automatic dropping will likely always be scope-based. In the rare case where you need to drop something before its owning scope completes, you can explicitly use `drop` as people have said downstream.
Borrows are a different story. Especially with mutable borrows (which are basically a static lock on the value), the current lexical restriction is too coarse-grained. There are always workarounds, but it will be nice when it's fixed :)
Re:Rust means never having to close a socket
by rcthompson on Friday October 10, 2014 @02:17PM
(#8439249)
Is there a specific reason for automatic dropping to be scope-based? Is it because dropping things could have side effects (e.g. closing a filehandle) and scope-based dropping makes it easy for someone looking at the code to determine when these side effects will occur?