Live data from Hacker News

My favorite Rust function

blog.jabid.in

1–10 of 197 posts

Re: My favorite Rust function

#4

There’s a number of fun C++ ones similar in spirit: std::move, for example.

std::move's implementation not quite as elegant, though (this is from the GCC source):

  template
    constexpr typename std::remove_reference::type&&
    move(_Tp&& __t) noexcept
    { return static_cast::type&&>(__t); }

Re: My favorite Rust function

#5
post #4

There’s a number of fun C++ ones similar in spirit: std::move, for example.

std::move's implementation not quite as elegant, though (this is from the GCC source): template constexpr typename std::remove_reference ::type&& move(_Tp&& __t) noexcept { return static_cast ::type&&>(__t); }

It’s a bit ugly because the standard library functions are replete with underscores, and of course it isn’t empty. But I still think it’s quite surprising, as most people would think it actually does some sort of semantic “move”.

Re: My favorite Rust function

#8
post #2

Wow, elegant. This was probably conceived as an idea during the design phase of the language, it seems right .

That same function appears on the second page of Philip Wadler's first Linear Logic paper, but it's called "kill" [1]

But I remember the words "drop" and "dup" being used since the early days of linear logic too. I believe they come from Forth, where they do pretty much the same thing! [2]

[1] http://homepages.inf.ed.ac.uk/wadler/papers/linear/linear.ps

[2] http://wiki.laptop.org/go/Forth_stack_operators

Re: My favorite Rust function

#9

There’s a number of fun C++ ones similar in spirit: std::move, for example.

The standard C++ way to free resources is the character '}'

Rust has the exact same semantics there. Drop is useful when you need to explicitly notate that a value should end its life early.
Post reply on HN