Closed digama0 closed 8 years ago
OK for now. FYI, eventually I'd kinda like to get rid of Deref for SegmentRef and make SegmentRef.segment private; nobody outside parser and segment_set should know that Segment objects exist
What's wrong with having Segment public with all private fields, and move the applicable API functions to Segment? Same for Statement(Ref).
The main argument was fragmentation; since most users will have a SegmentRef, they shouldn't have to think about whether the API they want is handled on SegmentRef or Segment. Although I suppose that argument goes away with a Deref impl.
Statement is a different case because there's very little you can do with a Statement if you don't also have references to the buffer
and the span_pool
. Since most of the API has to be on StatementRef anyway, and there's nobody outside parser that needs to handle raw Statements, I'd rather keep Statement as it is right now.
Er, this doesn't actually build, so I had to roll it back (where's the "reopen" button?)
Tried fixing the type error, discovered that this is actually a non-starter because the lifetime of Deref is wrong. Deref does not allow you to return a slice that potentially outlives the "smart reference"
@sorear Oops, forgot to build :/ I was actually aware of this issue; about half of the uses of TokenRef::slice
or SegmentRef::segment
are not replaceable with derefs because of lifetime constraints. Nevertheless, a lot of the time you just need some lifetime, in order to extract a Copy
value, and in these cases the deref is still useful.
StatementRef
was left off becauseStatement
is not public.