> Is using dummy struct fields for specifying custom type bounds on the struct itself really the best we can do in a brand-new language?
I as well wonder if there's a better way to do this (but I'm note the one to ask). > On a slightly different note, is there a strong reason for having to name lifetime parameters explicitly? I believe there exist situations where it makes sense for an item to have multiple lifetime parameters, though I can't think of one off the top of my head. On Thu, Jan 30, 2014 at 5:58 PM, Vadim <[email protected]> wrote: > Just wondering... Does anyone else feel that "syntax" around lifetimes > and type bounds is becoming very unwieldy? I am referring to this PR: > https://github.com/mozilla/rust/pull/11768. Is using dummy struct > fields for specifying custom type bounds on the struct itself really the > best we can do in a brand-new language? > > > At least for the lifetimes, Rust could extend existing syntax and allow > specifying them on by-value returns objects, so that, for example, this: > > pub trait MutableVector<'a, T> { > fn mut_iter(self) -> MutItems<'a, T>; > ... > } > > could be written as: > > pub trait MutableVector<'a, T> { > fn mut_iter(self) -> 'a MutItems<T>; > ... > } > > This also makes the intent much more clear. Currently, one would have to > dig into the definition of MutItems<'a,T> to figure out that the lifetime > parameter 'a is used to create a dummy borrow field into the vector, so > that the whole iterator is then treated as a mutable borrow. This feels > very convoluted, if you ask me. > > > On a slightly different note, is there a strong reason for having to name > lifetime parameters explicitly? Could we simply re-use actual parameter > names prefixed with ' as their lifetimes? The above could then be reduced > to this: > > pub trait MutableVector<T> { > fn mut_iter(self) -> 'self MutItems<T>; > ... > } > > This used to be valid syntax, btw, though it worked because 'self lifetime > was special, IIRC. > Note that I am not proposing to eliminate explicitly named lifetimes > entirely,- there are still cases when they are needed. But as far as I've > seen, those are few and far between. > > Thanks for reading, > Vadim > > > _______________________________________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/listinfo/rust-dev > >
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
