Hacker News new | ask | show | jobs
by scotty79 1261 days ago
I don't like how

fn func<'a>() means that 'a must outlive execution time of func

but

T:'a means that references contained in T must live longer than 'a

and

'a:'b means 'a must live longer than 'b (that's consistent at least)

Maybe:

    fn 'a:func() {
or

    fn func() 'a:{
would be better for indicating that 'a should outlive function execution.

Maybe some directional character would be better than : (> is probably out of question because of <> generics)

----

I feel like structs that don't have 'static lifetimes because they contain some borrows should have it indicated in their name.

For example:

    struct Handle&<'a> { n:&'a Node }
or even

    struct Handle&'a { n:&'a Node }
or

    struct Handle& 'a:{ n:&'a Node }
to indicate that 'a must outlive the struct.

Then you could use it:

    let h = Handle& { n: &some_node };
Maybe functions that create non-static struct might have & at the ends in their names.

Like

    vec![].into_iter().map()
but

    vec![].iter&().map()
    
You could easily see that you are dealing with something you should treat like a borrow because it contains borrows. Such structs would be sort of named, complex borrow and raw '&' borrow would be anonymous or naked borrow.

Not sure if it would also be nice to differentiate structs with &mut

----

I would just like to separate lifetimes syntax from generics syntax because those two things have nothing to do with each other from the point of view of the user of the language.

----

I would also like to have

while cond {} else {}

where else is only entered if cond was false from the start. But that's a wish not specific to Rust.