quick-xml icon indicating copy to clipboard operation
quick-xml copied to clipboard

Don't use 'a for the underlying slice's lifetime

Open stevenroose opened this issue 4 years ago • 3 comments

I'd like to make a proposal, just so I don't go implement it without having consensus on it being fine. Since 'a is kinda the default generic lifetime name, it's kinda annoying that it's also the one used for the "god slice" as I call it, the big &[u8] underlying a Reader. This makes that when a "ad-hoc temporary" lifetime is chosen, we will either (1) have to come up with another name because 'a is also used in the same context, or (2) use 'a with another meaning than all other 'as in the code.

So I'd like to propose using some kind of two-character lifetime name to indicate that it's a more permanent and cross-signature lifetime than 'a. Possible proposed names would be 'sl (for slice), or 'in (for input), or 'bf (for buffer), ...

I'd be wiling to do the work to use it everywhere, it helps me with the work I'm doing with fixing the borrows everywhere.

stevenroose avatar Oct 25 '21 21:10 stevenroose

Doing this would probably have avoided bug https://github.com/tafia/quick-xml/issues/332, f.e. as that is an example where 'a is used and it looks like it refers to the "god slice" lifetime, but is not.

stevenroose avatar Oct 25 '21 21:10 stevenroose

I really don't mind changing the lifetime names, in particular if it can avoid some bugs. I tend to prefer bf but feel free to pick another one, it'll always be better than 'a

tafia avatar Oct 26 '21 04:10 tafia

Yeah my only concern with 'bf is that it might be ambiguous since there is the &[u8] that is used as input, but for the buffered logic, there is also the buf: &mut Vec<u8>. So maybe we should use 'bf for things that borrow from that (explicitly so named) buffer and something like 'in for the input slice.

stevenroose avatar Oct 26 '21 08:10 stevenroose