For reference here is my related idea/request:
[https://users.rust-lang.org/t/short-lifetime-opposite-of-static/12136] basically for a ‘shortest lifetime’, which seems to be mentioned in this thread aswell;
My idea is shortest rather than shorter than any ; the use cases are safe. In my mind it is for a simple use case: passing temporaries into functions; the functions may not cache or duplicated them, they may only pass them internally. Another way to express it is ‘this reference cannot escape’
the recent case where it appeared for me: I was making a ‘window type’ that could accept a generic parameter for internal iteration of a hierarchy, but allowing that to be ‘a tuple of references’ (rather than ‘T’ and making the prototypes :&mut T etc) required the ‘window type’ to start specifying a manual lifetime parameter - even though this type was not part of the window, just part of an interface function.
Other than that I remember having to deal with lifetime annotations for another ‘internal iterator’ case (writing a ‘zipWith(a,b,f)’, a function taking a lambda, the lambda taking references to temporaries that the iterator-function would pass into it).
type SubWin = SubWindow<(&mut EdScene,&mut MTool)>;
//<<ERROR: need to start making a lifetime parameter
// part of the 'SubWIn' type, even though it's only intended as a temporary..
// the intent is there is never any 'PARAM' held persistently.
type BSubWin = Box<SubWin>;
trait SubWindow<PARAM> { //PARAM=app specific..
fn ask_size(&self)->Option<ViewPos>{None} // how much space does it want,
fn name(&self)->&str{"none"}
fn event(&mut self, p:PARAM, r:Rect, e:Event)->Option<()>;
fn render(&self, rc:&RC);
fn foreach_child(&self, r:Option<Rect>, f:&FnMut(&SubWin,Option<Rect>)->());
fn foreach_child_mut(&mut self, r:Option<Rect>, f:&FnMut(&mut SubWin,Option<Rect>)->());
}
… I had a workaround but if I could directly express the intent of 'shortest or 'temporary or whatever the best name is, it would have been more elegant
On another note, it might be helpful to have a #[unsafe(borrow_checker_is_warnings)] - automatically mark all the functions in this module as unsafe, still let the borrow checker do it’s work but make recommendations. Such code would not pollute the rust ecosystem as you’d still have to use an ‘unsafe{}’ block to call anything. then eventually we can meet in the middle once the ergonomics have been tweaked.
Sometimes we have patterns that we know work because they come from tried and tested scenarios , but it’s still hard to translate into rust; I do believe that it will be possible to make most scenarios easier to markup/specify than is possible at present;
regarding ease of reading and writing, and ‘the number of mental steps to do something’ - manually naming then tracking which names correspond to which item is more mental steps, and more to read past when trying to decipher what a piece of code actually does; I strongly believe a direct way of expressing the intent clearly would be superior - rather than ‘heres some general labels; the context-specific use of these labels implies…’
I do realise that the manual labelling allows some more complex use-cases in what I call ‘the middle ground’ to be handled both efficiently and safely; thats great , when you need it.
I found the labelling of 'static slightly counter intuitive, but having read the explanation, I think it does handle some of my cases. Completing the range of simple cases with simple explicit labels would be great.