Add lifetime-based ownership transfer
Submitted by Mikhail Zabaluev
Link to original bug (#737962)
Description
For return values and output parameters, the annotation (transfer none) means the caller gets a view into data owned elsewhere, which is valid, in the worst case, for as long as the caller does not do anything potentially mutative (assuming no concurrent access, which is an almost pervasive assumption in GLib anyway). This means that any sensible generated binding would copy out the returned value, which may be bad news for performance. Things like this keep us old C coders in business.
In Rust, however, there is a statically checked concept of reference lifetimes. For example, a reference to a member of a containing object could be imbued with the statically known lifetime of the container for the scope where the reference is obtained. For plenty more details, see here: http://doc.rust-lang.org/guide-lifetimes.html
Unfortunately, (out) (transfer none) is too pessimistic to make use of this feature of Rust. As an example, it applies to the result of g_environ_getenv(), where the string may be gone the next time something sets the same environment variable, but the globally mutable state is hidden by the API.
But there are other cases, like g_io_stream_get_input_stream(), where we might use the knowledge that the returned object pointer is valid for as long as we keep @stream around. To that end, the result of the function could be annotated with something like (transfer lifetime=stream) to refer to the parameter bestowing the lifetime on the returned object.