News for hackers. Stuff that matters.
Re:Rust 0.12.0 released by mbrubeck on Thursday October 09, 2014 @01:29PM (#8433829)
In cases where a function's input and output have the same lifetime, the lifetime is now inferred. So instead of this:

    fn f<'a>(x: &'a SomeType) -> &'a OtherType
you can now write this:

    fn f(x: &SomeType) -> &OtherType
Same meaning, just more concise syntax.
Re:Rust 0.12.0 released by thomasahle on Thursday October 09, 2014 @03:39PM (#8434606)
Uhm, what if I didn't want `&OtherType` to have the same lifetime? Would I then write:

    fn f<'a>(x: &'a SomeType) -> &'b OtherType

?
Re:Rust 0.12.0 released by kibwen on Thursday October 09, 2014 @03:58PM (#8434704)
That would be illegal, because it only makes sense to return a reference when that reference is somehow linked to the lifetime of an input parameter.

(Or when it has a lifetime of `static`, which means the referent is stored in static memory and thus is alive for the whole program.)

Re:Rust 0.12.0 released by thristian on Thursday October 09, 2014 @05:43PM (#8435164)
What if you're looking up the input in a temporary cache of some kind, and returning a reference to the cached value? The lifetime of the input and output would not be related in that scenario, but the output would not necessarily be 'static (maybe you build a cache, run some functions, tear it all down, then build a new cache with different values and do it all again).
Re:Rust 0.12.0 released by steveklabnik on Thursday October 09, 2014 @06:04PM (#8435260)
The lifetime would be matched to the lifetime of the cache, which has to be referred to somehow.
Re:Rust 0.12.0 released by thomasahle on Thursday October 09, 2014 @04:09PM (#8434759)
Ah cool, I still have a lot to learn about rust :)
Re:Rust 0.12.0 released by TD-Linux on Thursday October 09, 2014 @10:59PM (#8436037)
You wouldn't use a reference generally, if you're thinking of creating a new independent object you'd just return that. This is for cases when your return object is a reference into your argument, for example
Re:Rust 0.12.0 released by kimundi on Thursday October 09, 2014 @03:58PM (#8434703)
Yes, though this particular code would not compile because one of the lifetimes is not declared.
Re:Rust 0.12.0 released by untothebreach on Thursday October 09, 2014 @01:32PM (#8433853)
ah, got it. thanks!