31: Use standard generics for TextSize::of r=CAD97 a=CAD97
There is no specific reason to use APIT here, so prefer the form that allows more control for the user, in the form of the turbofish.
Co-authored-by: CAD97 <cad97@cad97.com>
29: TextSized is not meant to be used directly... r=matklad a=CAD97
so rename it to a name more distinct from TextSize.
Co-authored-by: CAD97 <cad97@cad97.com>
Remove `fn TextRange(` as that's slightly unusual and surprising,
which will add up to a lot of confusion over the long run.
Instead add:
* `new` as the biased, canonical way to create range from bounds
* `from_len` as an alternative ctor from starting position and len
* `empty` for empty ranges at a given offset
* `up_to` for ranges at zero offset with given length
* `default` for an empty range at zero
13: Alternative set of contains function r=CAD97 a=matklad
Motivation:
TextRange is a set, it contains elements (TextSize). For this reason,
for range-range op we use a more verbose `contains_range` name.
In stdlib, there's `HashSet::is_subset`. We used a similar design with
`is_subrage` before, but it was very confusing in practice -- you'll
have to lookup docs for which of lhs and rhs is sub and super set.
Additionally, exclusive semantics is a clear default with better
properties (if you have a partitioning of a range into subranges, only
one of the parts contains any given offset), so it make sense to call
it `contains` and reserve `contains_inclusive` for another op.
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
11: Switch to mathematical range notation r=matklad a=matklad
Just an option: `[10..20)` feel like a weird mix of rust and math. `[10, 20)` is just picking the math notation.
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Motivation:
TextRange is a set, it contains elements (TextSize). For this reason,
for range-range op we use a more verbose `contains_range` name.
In stdlib, there's `HashSet::is_subset`. We used a similar design with
`is_subrage` before, but it was very confusing in practice -- you'll
have to lookup docs for which of lhs and rhs is sub and super set.
Additionally, exclusive semantics is a clear default with better
properties (if you have a partitioning of a range into subranges, only
one of the parts contains any given offset), so it make sense to call
it `contains` and reserve `contains_inclusive` for another op.
6: Alternative set of conversions r=matklad a=matklad
@CAD97 what do yo think about this set of conversions? The idea here is that
* we provide From's for `u32`, because `TextSize` is, transparently, an `u32`.
* we don't provide other fixed sized conversions -- I don't think I've ever needed them, and `TextSize` is not exactly the number, so forcing the occasional user to two a two step conversion seems OK: first covnersions changes to a raw repr, the second conversion is a numeric cast. This is in contrast two a one-step conversion, which mixes both numeric cast and raw-typed.
* We provide `TryFrom<usize>` (because that can fail) and `Into<usize>` (because that can't fail. If you are on 16bit machine, you probably want to use u16 for TextSize anyway). Unlike stdlib, we can be more aggressive here.
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>