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.