22 Commits

Author SHA1 Message Date
Lukas Wirth
ae4b7f6c8f Reformat 2025-11-15 09:16:57 +02:00
Lukas Wirth
d46914fa78 Constify some constructors 2023-06-30 09:18:45 +02:00
Aleksey Kladov
e584bb8384 Fix docs 2020-04-25 11:38:10 +02:00
CAD97
d67af9b90b Scope trait TextLen just for primitives 2020-04-17 20:10:36 -04:00
CAD97
44492515ab Rename LenTextSize => TextLen
This way, it's a reasonable name to use.
2020-04-07 17:10:57 -04:00
Aleksey Kladov
4527c63db3 Merge pull request rust-analyzer/text-size#37 from CAD97/more-lentextsize
Don't blanket impl LenTextSize
2020-03-31 12:45:39 +02:00
CAD97
c9220dd18e Imporove test's impl LenTextSize for BadRope 2020-03-27 16:51:58 -04:00
CAD97
a39847804d Add test for indexing 2020-03-26 17:03:04 -04:00
CAD97
5d2c7a779d Don't blanket impl LenTextSize 2020-03-26 16:58:49 -04:00
CAD97
211ae81ad0 Tests to ensure common and auto trait presence 2020-03-23 17:03:43 -04:00
CAD97
5468ef0a9f Move construction tests into a test 2020-03-23 16:45:18 -04:00
Aleksey Kladov
8d9a1a4192 Make TextRange constructors more boring
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
2020-03-22 09:23:43 +01:00
Aleksey Kladov
0edd20912e Make intersect and cover into methods 2020-03-20 09:46:15 +01:00
Aleksey Kladov
bb763ae76a Check invariant during deserialization 2020-03-13 21:28:14 +01:00
bors[bot]
41299f705e Merge rust-analyzer/text-size#13
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>
2020-03-13 15:40:03 +00:00
CAD97
1341116d14 Provide generic ref-removing ops for TextSize 2020-03-13 10:42:46 -04:00
Aleksey Kladov
894afd0644 Alternative set of contains function
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.
2020-03-12 16:16:53 +01:00
CAD97
c1474fb51b fix tests 2020-03-11 23:27:12 -04:00
Aleksey Kladov
7d86273066 Tuple-struct ctor is the canonical way to create a ranges 2020-03-09 16:35:30 +01:00
Aleksey Kladov
416606929c Enforce invariant that ranges are well-formed
This is in contrast to `std::ops::Range`, which are not guaranteed to
be proper. For this reason, we have to lose `From` impls as well.
2020-03-09 08:39:40 +01:00
CAD97
2748c49ebe Scale back the exposed API surface 2020-03-07 22:33:21 -05:00
CAD97
18f7f27e60 Aggressive refactor 2020-03-07 17:10:37 -05:00