[rust-dev] returning functions in rust

Nakamura nnythm at gmail.com
Fri Jan 10 07:20:42 PST 2014

I'm new to rust, and tried going through some of the examples from the OS
class[0] that was taught in rust.  However, I got tripped up by the
exercise, "make a function that takes an integer n and another function |x|
-> x, and returns a function that is n applications of the original

I've been trying to see what the limits of rust are if you are using it
without the runtime/managed pointers etc, and it seems like I stumble
against one of the limits when trying to return functions.  The big
question is where to allocate the new function I want to return.

Like other people who are new to rust, I made the mistake of thinking that
lifetime parameters actually affecting lifetimes[1].  If this were the
case, it would be sensible to write this as a recursive function which has
the same lifetime as the function that you pass in.

Is there a safe way other than using managed pointers to return functions?
 It looks like you can use externs and call it a day (or you can maybe use
unsafe?  I haven't explored it yet), but that doesn't seem satisfactory.  I
saw a thread that mentioned unboxed closures, but couldn't find any other
details about them.  Maybe that's what I'm looking for?

If I do end up having to use managed pointers to return functions, will the
runtime infect everything I do, or could I just designate certain threads
(green or otherwise) gc-threads and go about my day on threads which don't
need to worry about gc?

[0]: http://rust-class.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140110/3becbdf5/attachment.html>

More information about the Rust-dev mailing list